@xata.io/client 0.0.0-alpha.vebf0406 → 0.0.0-alpha.ved00a04

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.cjs CHANGED
@@ -14,6 +14,13 @@ function isObject(value) {
14
14
  function isString(value) {
15
15
  return value !== void 0 && value !== null && typeof value === "string";
16
16
  }
17
+ function toBase64(value) {
18
+ try {
19
+ return btoa(value);
20
+ } catch (err) {
21
+ return Buffer.from(value).toString("base64");
22
+ }
23
+ }
17
24
 
18
25
  function getEnvVariable(name) {
19
26
  try {
@@ -273,6 +280,17 @@ const getBranchMetadata = (variables) => fetch$1({
273
280
  const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
274
281
  const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
275
282
  const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
283
+ const compareBranchSchema = (variables) => fetch$1({
284
+ url: "/db/{dbBranchName}/schema/compare/{branchName}",
285
+ method: "post",
286
+ ...variables
287
+ });
288
+ const updateBranchSchema = (variables) => fetch$1({
289
+ url: "/db/{dbBranchName}/schema/update",
290
+ method: "post",
291
+ ...variables
292
+ });
293
+ const getBranchSchemaHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables });
276
294
  const getBranchStats = (variables) => fetch$1({
277
295
  url: "/db/{dbBranchName}/stats",
278
296
  method: "get",
@@ -384,6 +402,9 @@ const operationsByTag = {
384
402
  getBranchMigrationHistory,
385
403
  executeBranchMigrationPlan,
386
404
  getBranchMigrationPlan,
405
+ compareBranchSchema,
406
+ updateBranchSchema,
407
+ getBranchSchemaHistory,
387
408
  getBranchStats
388
409
  },
389
410
  table: {
@@ -436,35 +457,35 @@ function isValidBuilder(builder) {
436
457
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
437
458
  }
438
459
 
439
- var __accessCheck$6 = (obj, member, msg) => {
460
+ var __accessCheck$7 = (obj, member, msg) => {
440
461
  if (!member.has(obj))
441
462
  throw TypeError("Cannot " + msg);
442
463
  };
443
- var __privateGet$5 = (obj, member, getter) => {
444
- __accessCheck$6(obj, member, "read from private field");
464
+ var __privateGet$6 = (obj, member, getter) => {
465
+ __accessCheck$7(obj, member, "read from private field");
445
466
  return getter ? getter.call(obj) : member.get(obj);
446
467
  };
447
- var __privateAdd$6 = (obj, member, value) => {
468
+ var __privateAdd$7 = (obj, member, value) => {
448
469
  if (member.has(obj))
449
470
  throw TypeError("Cannot add the same private member more than once");
450
471
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
451
472
  };
452
- var __privateSet$4 = (obj, member, value, setter) => {
453
- __accessCheck$6(obj, member, "write to private field");
473
+ var __privateSet$5 = (obj, member, value, setter) => {
474
+ __accessCheck$7(obj, member, "write to private field");
454
475
  setter ? setter.call(obj, value) : member.set(obj, value);
455
476
  return value;
456
477
  };
457
478
  var _extraProps, _namespaces;
458
479
  class XataApiClient {
459
480
  constructor(options = {}) {
460
- __privateAdd$6(this, _extraProps, void 0);
461
- __privateAdd$6(this, _namespaces, {});
481
+ __privateAdd$7(this, _extraProps, void 0);
482
+ __privateAdd$7(this, _namespaces, {});
462
483
  const provider = options.host ?? "production";
463
484
  const apiKey = options?.apiKey ?? getAPIKey();
464
485
  if (!apiKey) {
465
486
  throw new Error("Could not resolve a valid apiKey");
466
487
  }
467
- __privateSet$4(this, _extraProps, {
488
+ __privateSet$5(this, _extraProps, {
468
489
  apiUrl: getHostUrl(provider, "main"),
469
490
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
470
491
  fetchImpl: getFetchImplementation(options.fetch),
@@ -472,34 +493,34 @@ class XataApiClient {
472
493
  });
473
494
  }
474
495
  get user() {
475
- if (!__privateGet$5(this, _namespaces).user)
476
- __privateGet$5(this, _namespaces).user = new UserApi(__privateGet$5(this, _extraProps));
477
- return __privateGet$5(this, _namespaces).user;
496
+ if (!__privateGet$6(this, _namespaces).user)
497
+ __privateGet$6(this, _namespaces).user = new UserApi(__privateGet$6(this, _extraProps));
498
+ return __privateGet$6(this, _namespaces).user;
478
499
  }
479
500
  get workspaces() {
480
- if (!__privateGet$5(this, _namespaces).workspaces)
481
- __privateGet$5(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$5(this, _extraProps));
482
- return __privateGet$5(this, _namespaces).workspaces;
501
+ if (!__privateGet$6(this, _namespaces).workspaces)
502
+ __privateGet$6(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$6(this, _extraProps));
503
+ return __privateGet$6(this, _namespaces).workspaces;
483
504
  }
484
505
  get databases() {
485
- if (!__privateGet$5(this, _namespaces).databases)
486
- __privateGet$5(this, _namespaces).databases = new DatabaseApi(__privateGet$5(this, _extraProps));
487
- return __privateGet$5(this, _namespaces).databases;
506
+ if (!__privateGet$6(this, _namespaces).databases)
507
+ __privateGet$6(this, _namespaces).databases = new DatabaseApi(__privateGet$6(this, _extraProps));
508
+ return __privateGet$6(this, _namespaces).databases;
488
509
  }
489
510
  get branches() {
490
- if (!__privateGet$5(this, _namespaces).branches)
491
- __privateGet$5(this, _namespaces).branches = new BranchApi(__privateGet$5(this, _extraProps));
492
- return __privateGet$5(this, _namespaces).branches;
511
+ if (!__privateGet$6(this, _namespaces).branches)
512
+ __privateGet$6(this, _namespaces).branches = new BranchApi(__privateGet$6(this, _extraProps));
513
+ return __privateGet$6(this, _namespaces).branches;
493
514
  }
494
515
  get tables() {
495
- if (!__privateGet$5(this, _namespaces).tables)
496
- __privateGet$5(this, _namespaces).tables = new TableApi(__privateGet$5(this, _extraProps));
497
- return __privateGet$5(this, _namespaces).tables;
516
+ if (!__privateGet$6(this, _namespaces).tables)
517
+ __privateGet$6(this, _namespaces).tables = new TableApi(__privateGet$6(this, _extraProps));
518
+ return __privateGet$6(this, _namespaces).tables;
498
519
  }
499
520
  get records() {
500
- if (!__privateGet$5(this, _namespaces).records)
501
- __privateGet$5(this, _namespaces).records = new RecordsApi(__privateGet$5(this, _extraProps));
502
- return __privateGet$5(this, _namespaces).records;
521
+ if (!__privateGet$6(this, _namespaces).records)
522
+ __privateGet$6(this, _namespaces).records = new RecordsApi(__privateGet$6(this, _extraProps));
523
+ return __privateGet$6(this, _namespaces).records;
503
524
  }
504
525
  }
505
526
  _extraProps = new WeakMap();
@@ -854,43 +875,43 @@ class XataApiPlugin {
854
875
  class XataPlugin {
855
876
  }
856
877
 
857
- var __accessCheck$5 = (obj, member, msg) => {
878
+ var __accessCheck$6 = (obj, member, msg) => {
858
879
  if (!member.has(obj))
859
880
  throw TypeError("Cannot " + msg);
860
881
  };
861
- var __privateGet$4 = (obj, member, getter) => {
862
- __accessCheck$5(obj, member, "read from private field");
882
+ var __privateGet$5 = (obj, member, getter) => {
883
+ __accessCheck$6(obj, member, "read from private field");
863
884
  return getter ? getter.call(obj) : member.get(obj);
864
885
  };
865
- var __privateAdd$5 = (obj, member, value) => {
886
+ var __privateAdd$6 = (obj, member, value) => {
866
887
  if (member.has(obj))
867
888
  throw TypeError("Cannot add the same private member more than once");
868
889
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
869
890
  };
870
- var __privateSet$3 = (obj, member, value, setter) => {
871
- __accessCheck$5(obj, member, "write to private field");
891
+ var __privateSet$4 = (obj, member, value, setter) => {
892
+ __accessCheck$6(obj, member, "write to private field");
872
893
  setter ? setter.call(obj, value) : member.set(obj, value);
873
894
  return value;
874
895
  };
875
896
  var _query;
876
897
  class Page {
877
898
  constructor(query, meta, records = []) {
878
- __privateAdd$5(this, _query, void 0);
879
- __privateSet$3(this, _query, query);
899
+ __privateAdd$6(this, _query, void 0);
900
+ __privateSet$4(this, _query, query);
880
901
  this.meta = meta;
881
902
  this.records = records;
882
903
  }
883
904
  async nextPage(size, offset) {
884
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
905
+ return __privateGet$5(this, _query).getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
885
906
  }
886
907
  async previousPage(size, offset) {
887
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
908
+ return __privateGet$5(this, _query).getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
888
909
  }
889
910
  async firstPage(size, offset) {
890
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
911
+ return __privateGet$5(this, _query).getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
891
912
  }
892
913
  async lastPage(size, offset) {
893
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
914
+ return __privateGet$5(this, _query).getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
894
915
  }
895
916
  hasNextPage() {
896
917
  return this.meta.page.more;
@@ -902,46 +923,47 @@ const PAGINATION_DEFAULT_SIZE = 200;
902
923
  const PAGINATION_MAX_OFFSET = 800;
903
924
  const PAGINATION_DEFAULT_OFFSET = 0;
904
925
 
905
- var __accessCheck$4 = (obj, member, msg) => {
926
+ var __accessCheck$5 = (obj, member, msg) => {
906
927
  if (!member.has(obj))
907
928
  throw TypeError("Cannot " + msg);
908
929
  };
909
- var __privateGet$3 = (obj, member, getter) => {
910
- __accessCheck$4(obj, member, "read from private field");
930
+ var __privateGet$4 = (obj, member, getter) => {
931
+ __accessCheck$5(obj, member, "read from private field");
911
932
  return getter ? getter.call(obj) : member.get(obj);
912
933
  };
913
- var __privateAdd$4 = (obj, member, value) => {
934
+ var __privateAdd$5 = (obj, member, value) => {
914
935
  if (member.has(obj))
915
936
  throw TypeError("Cannot add the same private member more than once");
916
937
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
917
938
  };
918
- var __privateSet$2 = (obj, member, value, setter) => {
919
- __accessCheck$4(obj, member, "write to private field");
939
+ var __privateSet$3 = (obj, member, value, setter) => {
940
+ __accessCheck$5(obj, member, "write to private field");
920
941
  setter ? setter.call(obj, value) : member.set(obj, value);
921
942
  return value;
922
943
  };
923
944
  var _table$1, _repository, _data;
924
945
  const _Query = class {
925
946
  constructor(repository, table, data, parent) {
926
- __privateAdd$4(this, _table$1, void 0);
927
- __privateAdd$4(this, _repository, void 0);
928
- __privateAdd$4(this, _data, { filter: {} });
947
+ __privateAdd$5(this, _table$1, void 0);
948
+ __privateAdd$5(this, _repository, void 0);
949
+ __privateAdd$5(this, _data, { filter: {} });
929
950
  this.meta = { page: { cursor: "start", more: true } };
930
951
  this.records = [];
931
- __privateSet$2(this, _table$1, table);
952
+ __privateSet$3(this, _table$1, table);
932
953
  if (repository) {
933
- __privateSet$2(this, _repository, repository);
954
+ __privateSet$3(this, _repository, repository);
934
955
  } else {
935
- __privateSet$2(this, _repository, this);
956
+ __privateSet$3(this, _repository, this);
936
957
  }
937
- __privateGet$3(this, _data).filter = data.filter ?? parent?.filter ?? {};
938
- __privateGet$3(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
939
- __privateGet$3(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
940
- __privateGet$3(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
941
- __privateGet$3(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
942
- __privateGet$3(this, _data).sort = data.sort ?? parent?.sort;
943
- __privateGet$3(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
944
- __privateGet$3(this, _data).page = data.page ?? parent?.page;
958
+ __privateGet$4(this, _data).filter = data.filter ?? parent?.filter ?? {};
959
+ __privateGet$4(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
960
+ __privateGet$4(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
961
+ __privateGet$4(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
962
+ __privateGet$4(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
963
+ __privateGet$4(this, _data).sort = data.sort ?? parent?.sort;
964
+ __privateGet$4(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
965
+ __privateGet$4(this, _data).page = data.page ?? parent?.page;
966
+ __privateGet$4(this, _data).cache = data.cache ?? parent?.cache;
945
967
  this.any = this.any.bind(this);
946
968
  this.all = this.all.bind(this);
947
969
  this.not = this.not.bind(this);
@@ -952,45 +974,50 @@ const _Query = class {
952
974
  Object.defineProperty(this, "repository", { enumerable: false });
953
975
  }
954
976
  getQueryOptions() {
955
- return __privateGet$3(this, _data);
977
+ return __privateGet$4(this, _data);
978
+ }
979
+ key() {
980
+ const { columns = [], filter = {}, sort = [], page = {} } = __privateGet$4(this, _data);
981
+ const key = JSON.stringify({ columns, filter, sort, page });
982
+ return toBase64(key);
956
983
  }
957
984
  any(...queries) {
958
985
  const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
959
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $any } }, __privateGet$3(this, _data));
986
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $any } }, __privateGet$4(this, _data));
960
987
  }
961
988
  all(...queries) {
962
989
  const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
963
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
990
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
964
991
  }
965
992
  not(...queries) {
966
993
  const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
967
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $not } }, __privateGet$3(this, _data));
994
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $not } }, __privateGet$4(this, _data));
968
995
  }
969
996
  none(...queries) {
970
997
  const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
971
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $none } }, __privateGet$3(this, _data));
998
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $none } }, __privateGet$4(this, _data));
972
999
  }
973
1000
  filter(a, b) {
974
1001
  if (arguments.length === 1) {
975
1002
  const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
976
- const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat(constraints));
977
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
1003
+ const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat(constraints));
1004
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
978
1005
  } else {
979
- const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
980
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
1006
+ const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
1007
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
981
1008
  }
982
1009
  }
983
1010
  sort(column, direction) {
984
- const originalSort = [__privateGet$3(this, _data).sort ?? []].flat();
1011
+ const originalSort = [__privateGet$4(this, _data).sort ?? []].flat();
985
1012
  const sort = [...originalSort, { column, direction }];
986
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { sort }, __privateGet$3(this, _data));
1013
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { sort }, __privateGet$4(this, _data));
987
1014
  }
988
1015
  select(columns) {
989
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { columns }, __privateGet$3(this, _data));
1016
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { columns }, __privateGet$4(this, _data));
990
1017
  }
991
1018
  getPaginated(options = {}) {
992
- const query = new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), options, __privateGet$3(this, _data));
993
- return __privateGet$3(this, _repository).query(query);
1019
+ const query = new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), options, __privateGet$4(this, _data));
1020
+ return __privateGet$4(this, _repository).query(query);
994
1021
  }
995
1022
  async *[Symbol.asyncIterator]() {
996
1023
  for await (const [record] of this.getIterator(1)) {
@@ -1018,10 +1045,13 @@ const _Query = class {
1018
1045
  }
1019
1046
  return results;
1020
1047
  }
1021
- async getOne(options = {}) {
1048
+ async getFirst(options = {}) {
1022
1049
  const records = await this.getMany({ ...options, page: { size: 1 } });
1023
1050
  return records[0] || null;
1024
1051
  }
1052
+ cache(ttl) {
1053
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { cache: ttl }, __privateGet$4(this, _data));
1054
+ }
1025
1055
  nextPage(size, offset) {
1026
1056
  return this.firstPage(size, offset);
1027
1057
  }
@@ -1073,75 +1103,93 @@ function buildSortFilter(filter) {
1073
1103
  }
1074
1104
  }
1075
1105
 
1076
- var __accessCheck$3 = (obj, member, msg) => {
1106
+ var __accessCheck$4 = (obj, member, msg) => {
1077
1107
  if (!member.has(obj))
1078
1108
  throw TypeError("Cannot " + msg);
1079
1109
  };
1080
- var __privateGet$2 = (obj, member, getter) => {
1081
- __accessCheck$3(obj, member, "read from private field");
1110
+ var __privateGet$3 = (obj, member, getter) => {
1111
+ __accessCheck$4(obj, member, "read from private field");
1082
1112
  return getter ? getter.call(obj) : member.get(obj);
1083
1113
  };
1084
- var __privateAdd$3 = (obj, member, value) => {
1114
+ var __privateAdd$4 = (obj, member, value) => {
1085
1115
  if (member.has(obj))
1086
1116
  throw TypeError("Cannot add the same private member more than once");
1087
1117
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1088
1118
  };
1089
- var __privateSet$1 = (obj, member, value, setter) => {
1090
- __accessCheck$3(obj, member, "write to private field");
1119
+ var __privateSet$2 = (obj, member, value, setter) => {
1120
+ __accessCheck$4(obj, member, "write to private field");
1091
1121
  setter ? setter.call(obj, value) : member.set(obj, value);
1092
1122
  return value;
1093
1123
  };
1094
1124
  var __privateMethod$2 = (obj, member, method) => {
1095
- __accessCheck$3(obj, member, "access private method");
1125
+ __accessCheck$4(obj, member, "access private method");
1096
1126
  return method;
1097
1127
  };
1098
- var _table, _links, _getFetchProps, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn;
1128
+ var _table, _links, _getFetchProps, _cache, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _invalidateCache, invalidateCache_fn, _setCacheRecord, setCacheRecord_fn, _getCacheRecord, getCacheRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn;
1099
1129
  class Repository extends Query {
1100
1130
  }
1101
1131
  class RestRepository extends Query {
1102
1132
  constructor(options) {
1103
1133
  super(null, options.table, {});
1104
- __privateAdd$3(this, _insertRecordWithoutId);
1105
- __privateAdd$3(this, _insertRecordWithId);
1106
- __privateAdd$3(this, _bulkInsertTableRecords);
1107
- __privateAdd$3(this, _updateRecordWithID);
1108
- __privateAdd$3(this, _upsertRecordWithID);
1109
- __privateAdd$3(this, _deleteRecord);
1110
- __privateAdd$3(this, _table, void 0);
1111
- __privateAdd$3(this, _links, void 0);
1112
- __privateAdd$3(this, _getFetchProps, void 0);
1113
- __privateSet$1(this, _table, options.table);
1114
- __privateSet$1(this, _links, options.links ?? {});
1115
- __privateSet$1(this, _getFetchProps, options.getFetchProps);
1134
+ __privateAdd$4(this, _insertRecordWithoutId);
1135
+ __privateAdd$4(this, _insertRecordWithId);
1136
+ __privateAdd$4(this, _bulkInsertTableRecords);
1137
+ __privateAdd$4(this, _updateRecordWithID);
1138
+ __privateAdd$4(this, _upsertRecordWithID);
1139
+ __privateAdd$4(this, _deleteRecord);
1140
+ __privateAdd$4(this, _invalidateCache);
1141
+ __privateAdd$4(this, _setCacheRecord);
1142
+ __privateAdd$4(this, _getCacheRecord);
1143
+ __privateAdd$4(this, _setCacheQuery);
1144
+ __privateAdd$4(this, _getCacheQuery);
1145
+ __privateAdd$4(this, _table, void 0);
1146
+ __privateAdd$4(this, _links, void 0);
1147
+ __privateAdd$4(this, _getFetchProps, void 0);
1148
+ __privateAdd$4(this, _cache, void 0);
1149
+ __privateSet$2(this, _table, options.table);
1150
+ __privateSet$2(this, _links, options.links ?? {});
1151
+ __privateSet$2(this, _getFetchProps, options.pluginOptions.getFetchProps);
1116
1152
  this.db = options.db;
1153
+ __privateSet$2(this, _cache, options.pluginOptions.cache);
1117
1154
  }
1118
1155
  async create(a, b) {
1119
1156
  if (Array.isArray(a)) {
1120
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1157
+ const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1158
+ await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1159
+ return records;
1121
1160
  }
1122
1161
  if (isString(a) && isObject(b)) {
1123
1162
  if (a === "")
1124
1163
  throw new Error("The id can't be empty");
1125
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1164
+ const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1165
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1166
+ return record;
1126
1167
  }
1127
1168
  if (isObject(a) && isString(a.id)) {
1128
1169
  if (a.id === "")
1129
1170
  throw new Error("The id can't be empty");
1130
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1171
+ const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1172
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1173
+ return record;
1131
1174
  }
1132
1175
  if (isObject(a)) {
1133
- return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1176
+ const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1177
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1178
+ return record;
1134
1179
  }
1135
1180
  throw new Error("Invalid arguments for create method");
1136
1181
  }
1137
1182
  async read(recordId) {
1138
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1183
+ const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, recordId);
1184
+ if (cacheRecord)
1185
+ return cacheRecord;
1186
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1139
1187
  try {
1140
1188
  const response = await getRecord({
1141
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1189
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1142
1190
  ...fetchProps
1143
1191
  });
1144
- return initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), response);
1192
+ return initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), response);
1145
1193
  } catch (e) {
1146
1194
  if (isObject(e) && e.status === 404) {
1147
1195
  return null;
@@ -1157,10 +1205,16 @@ class RestRepository extends Query {
1157
1205
  return Promise.all(a.map((object) => this.update(object)));
1158
1206
  }
1159
1207
  if (isString(a) && isObject(b)) {
1160
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1208
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1209
+ const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1210
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1211
+ return record;
1161
1212
  }
1162
1213
  if (isObject(a) && isString(a.id)) {
1163
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1214
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1215
+ const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1216
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1217
+ return record;
1164
1218
  }
1165
1219
  throw new Error("Invalid arguments for update method");
1166
1220
  }
@@ -1172,41 +1226,52 @@ class RestRepository extends Query {
1172
1226
  return Promise.all(a.map((object) => this.createOrUpdate(object)));
1173
1227
  }
1174
1228
  if (isString(a) && isObject(b)) {
1175
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1229
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1230
+ const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1231
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1232
+ return record;
1176
1233
  }
1177
1234
  if (isObject(a) && isString(a.id)) {
1178
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1235
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1236
+ const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1237
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1238
+ return record;
1179
1239
  }
1180
1240
  throw new Error("Invalid arguments for createOrUpdate method");
1181
1241
  }
1182
- async delete(recordId) {
1183
- if (Array.isArray(recordId)) {
1184
- if (recordId.length > 100) {
1242
+ async delete(a) {
1243
+ if (Array.isArray(a)) {
1244
+ if (a.length > 100) {
1185
1245
  console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1186
1246
  }
1187
- await Promise.all(recordId.map((id) => this.delete(id)));
1247
+ await Promise.all(a.map((id) => this.delete(id)));
1188
1248
  return;
1189
1249
  }
1190
- if (isString(recordId)) {
1191
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, recordId);
1250
+ if (isString(a)) {
1251
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1252
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1192
1253
  return;
1193
1254
  }
1194
- if (isObject(recordId) && isString(recordId.id)) {
1195
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, recordId.id);
1255
+ if (isObject(a) && isString(a.id)) {
1256
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1257
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1196
1258
  return;
1197
1259
  }
1198
1260
  throw new Error("Invalid arguments for delete method");
1199
1261
  }
1200
1262
  async search(query, options = {}) {
1201
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1263
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1202
1264
  const { records } = await searchBranch({
1203
1265
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1204
- body: { tables: [__privateGet$2(this, _table)], query, fuzziness: options.fuzziness },
1266
+ body: { tables: [__privateGet$3(this, _table)], query, fuzziness: options.fuzziness },
1205
1267
  ...fetchProps
1206
1268
  });
1207
- return records.map((item) => initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), item));
1269
+ return records.map((item) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), item));
1208
1270
  }
1209
1271
  async query(query) {
1272
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1273
+ if (cacheQuery)
1274
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
1210
1275
  const data = query.getQueryOptions();
1211
1276
  const body = {
1212
1277
  filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
@@ -1214,28 +1279,30 @@ class RestRepository extends Query {
1214
1279
  page: data.page,
1215
1280
  columns: data.columns
1216
1281
  };
1217
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1282
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1218
1283
  const { meta, records: objects } = await queryTable({
1219
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table) },
1284
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
1220
1285
  body,
1221
1286
  ...fetchProps
1222
1287
  });
1223
- const records = objects.map((record) => initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), record));
1288
+ const records = objects.map((record) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), record));
1289
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1224
1290
  return new Page(query, meta, records);
1225
1291
  }
1226
1292
  }
1227
1293
  _table = new WeakMap();
1228
1294
  _links = new WeakMap();
1229
1295
  _getFetchProps = new WeakMap();
1296
+ _cache = new WeakMap();
1230
1297
  _insertRecordWithoutId = new WeakSet();
1231
1298
  insertRecordWithoutId_fn = async function(object) {
1232
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1299
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1233
1300
  const record = transformObjectLinks(object);
1234
1301
  const response = await insertRecord({
1235
1302
  pathParams: {
1236
1303
  workspace: "{workspaceId}",
1237
1304
  dbBranchName: "{dbBranch}",
1238
- tableName: __privateGet$2(this, _table)
1305
+ tableName: __privateGet$3(this, _table)
1239
1306
  },
1240
1307
  body: record,
1241
1308
  ...fetchProps
@@ -1248,13 +1315,13 @@ insertRecordWithoutId_fn = async function(object) {
1248
1315
  };
1249
1316
  _insertRecordWithId = new WeakSet();
1250
1317
  insertRecordWithId_fn = async function(recordId, object) {
1251
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1318
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1252
1319
  const record = transformObjectLinks(object);
1253
1320
  const response = await insertRecordWithID({
1254
1321
  pathParams: {
1255
1322
  workspace: "{workspaceId}",
1256
1323
  dbBranchName: "{dbBranch}",
1257
- tableName: __privateGet$2(this, _table),
1324
+ tableName: __privateGet$3(this, _table),
1258
1325
  recordId
1259
1326
  },
1260
1327
  body: record,
@@ -1269,10 +1336,10 @@ insertRecordWithId_fn = async function(recordId, object) {
1269
1336
  };
1270
1337
  _bulkInsertTableRecords = new WeakSet();
1271
1338
  bulkInsertTableRecords_fn = async function(objects) {
1272
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1339
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1273
1340
  const records = objects.map((object) => transformObjectLinks(object));
1274
1341
  const response = await bulkInsertTableRecords({
1275
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table) },
1342
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
1276
1343
  body: { records },
1277
1344
  ...fetchProps
1278
1345
  });
@@ -1284,10 +1351,10 @@ bulkInsertTableRecords_fn = async function(objects) {
1284
1351
  };
1285
1352
  _updateRecordWithID = new WeakSet();
1286
1353
  updateRecordWithID_fn = async function(recordId, object) {
1287
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1354
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1288
1355
  const record = transformObjectLinks(object);
1289
1356
  const response = await updateRecordWithID({
1290
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1357
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1291
1358
  body: record,
1292
1359
  ...fetchProps
1293
1360
  });
@@ -1298,9 +1365,9 @@ updateRecordWithID_fn = async function(recordId, object) {
1298
1365
  };
1299
1366
  _upsertRecordWithID = new WeakSet();
1300
1367
  upsertRecordWithID_fn = async function(recordId, object) {
1301
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1368
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1302
1369
  const response = await upsertRecordWithID({
1303
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1370
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1304
1371
  body: object,
1305
1372
  ...fetchProps
1306
1373
  });
@@ -1311,12 +1378,51 @@ upsertRecordWithID_fn = async function(recordId, object) {
1311
1378
  };
1312
1379
  _deleteRecord = new WeakSet();
1313
1380
  deleteRecord_fn = async function(recordId) {
1314
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1381
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1315
1382
  await deleteRecord({
1316
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1383
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1317
1384
  ...fetchProps
1318
1385
  });
1319
1386
  };
1387
+ _invalidateCache = new WeakSet();
1388
+ invalidateCache_fn = async function(recordId) {
1389
+ await __privateGet$3(this, _cache).delete(`rec_${__privateGet$3(this, _table)}:${recordId}`);
1390
+ const cacheItems = await __privateGet$3(this, _cache).getAll();
1391
+ const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1392
+ for (const [key, value] of queries) {
1393
+ const ids = getIds(value);
1394
+ if (ids.includes(recordId))
1395
+ await __privateGet$3(this, _cache).delete(key);
1396
+ }
1397
+ };
1398
+ _setCacheRecord = new WeakSet();
1399
+ setCacheRecord_fn = async function(record) {
1400
+ if (!__privateGet$3(this, _cache).cacheRecords)
1401
+ return;
1402
+ await __privateGet$3(this, _cache).set(`rec_${__privateGet$3(this, _table)}:${record.id}`, record);
1403
+ };
1404
+ _getCacheRecord = new WeakSet();
1405
+ getCacheRecord_fn = async function(recordId) {
1406
+ if (!__privateGet$3(this, _cache).cacheRecords)
1407
+ return null;
1408
+ return __privateGet$3(this, _cache).get(`rec_${__privateGet$3(this, _table)}:${recordId}`);
1409
+ };
1410
+ _setCacheQuery = new WeakSet();
1411
+ setCacheQuery_fn = async function(query, meta, records) {
1412
+ await __privateGet$3(this, _cache).set(`query_${__privateGet$3(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
1413
+ };
1414
+ _getCacheQuery = new WeakSet();
1415
+ getCacheQuery_fn = async function(query) {
1416
+ const key = `query_${__privateGet$3(this, _table)}:${query.key()}`;
1417
+ const result = await __privateGet$3(this, _cache).get(key);
1418
+ if (!result)
1419
+ return null;
1420
+ const { cache: ttl = __privateGet$3(this, _cache).defaultQueryTTL } = query.getQueryOptions();
1421
+ if (!ttl || ttl < 0)
1422
+ return result;
1423
+ const hasExpired = result.date.getTime() + ttl < Date.now();
1424
+ return hasExpired ? null : result;
1425
+ };
1320
1426
  const transformObjectLinks = (object) => {
1321
1427
  return Object.entries(object).reduce((acc, [key, value]) => {
1322
1428
  if (key === "xata")
@@ -1350,6 +1456,65 @@ const initObject = (db, links, table, object) => {
1350
1456
  Object.freeze(result);
1351
1457
  return result;
1352
1458
  };
1459
+ function getIds(value) {
1460
+ if (Array.isArray(value)) {
1461
+ return value.map((item) => getIds(item)).flat();
1462
+ }
1463
+ if (!isObject(value))
1464
+ return [];
1465
+ const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1466
+ return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
1467
+ }
1468
+
1469
+ var __accessCheck$3 = (obj, member, msg) => {
1470
+ if (!member.has(obj))
1471
+ throw TypeError("Cannot " + msg);
1472
+ };
1473
+ var __privateGet$2 = (obj, member, getter) => {
1474
+ __accessCheck$3(obj, member, "read from private field");
1475
+ return getter ? getter.call(obj) : member.get(obj);
1476
+ };
1477
+ var __privateAdd$3 = (obj, member, value) => {
1478
+ if (member.has(obj))
1479
+ throw TypeError("Cannot add the same private member more than once");
1480
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1481
+ };
1482
+ var __privateSet$1 = (obj, member, value, setter) => {
1483
+ __accessCheck$3(obj, member, "write to private field");
1484
+ setter ? setter.call(obj, value) : member.set(obj, value);
1485
+ return value;
1486
+ };
1487
+ var _map;
1488
+ class SimpleCache {
1489
+ constructor(options = {}) {
1490
+ __privateAdd$3(this, _map, void 0);
1491
+ __privateSet$1(this, _map, /* @__PURE__ */ new Map());
1492
+ this.capacity = options.max ?? 500;
1493
+ this.cacheRecords = options.cacheRecords ?? true;
1494
+ this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1495
+ }
1496
+ async getAll() {
1497
+ return Object.fromEntries(__privateGet$2(this, _map));
1498
+ }
1499
+ async get(key) {
1500
+ return __privateGet$2(this, _map).get(key) ?? null;
1501
+ }
1502
+ async set(key, value) {
1503
+ await this.delete(key);
1504
+ __privateGet$2(this, _map).set(key, value);
1505
+ if (__privateGet$2(this, _map).size > this.capacity) {
1506
+ const leastRecentlyUsed = __privateGet$2(this, _map).keys().next().value;
1507
+ await this.delete(leastRecentlyUsed);
1508
+ }
1509
+ }
1510
+ async delete(key) {
1511
+ __privateGet$2(this, _map).delete(key);
1512
+ }
1513
+ async clear() {
1514
+ return __privateGet$2(this, _map).clear();
1515
+ }
1516
+ }
1517
+ _map = new WeakMap();
1353
1518
 
1354
1519
  const gt = (value) => ({ $gt: value });
1355
1520
  const ge = (value) => ({ $ge: value });
@@ -1391,20 +1556,20 @@ class SchemaPlugin extends XataPlugin {
1391
1556
  this.tableNames = tableNames;
1392
1557
  __privateAdd$2(this, _tables, {});
1393
1558
  }
1394
- build(options) {
1395
- const { getFetchProps } = options;
1559
+ build(pluginOptions) {
1396
1560
  const links = this.links;
1397
1561
  const db = new Proxy({}, {
1398
1562
  get: (_target, table) => {
1399
1563
  if (!isString(table))
1400
1564
  throw new Error("Invalid table name");
1401
- if (!__privateGet$1(this, _tables)[table])
1402
- __privateGet$1(this, _tables)[table] = new RestRepository({ db, getFetchProps, table, links });
1565
+ if (!__privateGet$1(this, _tables)[table]) {
1566
+ __privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, links });
1567
+ }
1403
1568
  return __privateGet$1(this, _tables)[table];
1404
1569
  }
1405
1570
  });
1406
1571
  for (const table of this.tableNames ?? []) {
1407
- db[table] = new RestRepository({ db, getFetchProps, table, links });
1572
+ db[table] = new RestRepository({ db, pluginOptions, table, links });
1408
1573
  }
1409
1574
  return db;
1410
1575
  }
@@ -1578,16 +1743,18 @@ const buildClient = (plugins) => {
1578
1743
  __privateAdd(this, _evaluateBranch);
1579
1744
  __privateAdd(this, _branch, void 0);
1580
1745
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
1581
- const db = new SchemaPlugin(links, tables).build({ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions) });
1582
- const search = new SearchPlugin(db, links ?? {}).build({
1583
- getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions)
1584
- });
1746
+ const pluginOptions = {
1747
+ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
1748
+ cache: safeOptions.cache
1749
+ };
1750
+ const db = new SchemaPlugin(links, tables).build(pluginOptions);
1751
+ const search = new SearchPlugin(db, links ?? {}).build(pluginOptions);
1585
1752
  this.db = db;
1586
1753
  this.search = search;
1587
1754
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
1588
1755
  if (!namespace)
1589
1756
  continue;
1590
- const result = namespace.build({ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions) });
1757
+ const result = namespace.build(pluginOptions);
1591
1758
  if (result instanceof Promise) {
1592
1759
  void result.then((namespace2) => {
1593
1760
  this[key] = namespace2;
@@ -1601,11 +1768,12 @@ const buildClient = (plugins) => {
1601
1768
  const fetch = getFetchImplementation(options?.fetch);
1602
1769
  const databaseURL = options?.databaseURL || getDatabaseURL();
1603
1770
  const apiKey = options?.apiKey || getAPIKey();
1771
+ const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
1604
1772
  const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
1605
1773
  if (!databaseURL || !apiKey) {
1606
1774
  throw new Error("Options databaseURL and apiKey are required");
1607
1775
  }
1608
- return { fetch, databaseURL, apiKey, branch };
1776
+ return { fetch, databaseURL, apiKey, branch, cache };
1609
1777
  }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
1610
1778
  fetch,
1611
1779
  apiKey,
@@ -1665,6 +1833,7 @@ exports.Repository = Repository;
1665
1833
  exports.RestRepository = RestRepository;
1666
1834
  exports.SchemaPlugin = SchemaPlugin;
1667
1835
  exports.SearchPlugin = SearchPlugin;
1836
+ exports.SimpleCache = SimpleCache;
1668
1837
  exports.XataApiClient = XataApiClient;
1669
1838
  exports.XataApiPlugin = XataApiPlugin;
1670
1839
  exports.XataError = XataError;
@@ -1674,6 +1843,7 @@ exports.addTableColumn = addTableColumn;
1674
1843
  exports.buildClient = buildClient;
1675
1844
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
1676
1845
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
1846
+ exports.compareBranchSchema = compareBranchSchema;
1677
1847
  exports.contains = contains;
1678
1848
  exports.createBranch = createBranch;
1679
1849
  exports.createDatabase = createDatabase;
@@ -1698,6 +1868,7 @@ exports.getBranchList = getBranchList;
1698
1868
  exports.getBranchMetadata = getBranchMetadata;
1699
1869
  exports.getBranchMigrationHistory = getBranchMigrationHistory;
1700
1870
  exports.getBranchMigrationPlan = getBranchMigrationPlan;
1871
+ exports.getBranchSchemaHistory = getBranchSchemaHistory;
1701
1872
  exports.getBranchStats = getBranchStats;
1702
1873
  exports.getColumn = getColumn;
1703
1874
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
@@ -1738,6 +1909,7 @@ exports.searchBranch = searchBranch;
1738
1909
  exports.setTableSchema = setTableSchema;
1739
1910
  exports.startsWith = startsWith;
1740
1911
  exports.updateBranchMetadata = updateBranchMetadata;
1912
+ exports.updateBranchSchema = updateBranchSchema;
1741
1913
  exports.updateColumn = updateColumn;
1742
1914
  exports.updateRecordWithID = updateRecordWithID;
1743
1915
  exports.updateTable = updateTable;