@xata.io/client 0.8.4 → 0.9.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/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 {
@@ -436,35 +443,35 @@ function isValidBuilder(builder) {
436
443
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
437
444
  }
438
445
 
439
- var __accessCheck$6 = (obj, member, msg) => {
446
+ var __accessCheck$7 = (obj, member, msg) => {
440
447
  if (!member.has(obj))
441
448
  throw TypeError("Cannot " + msg);
442
449
  };
443
- var __privateGet$5 = (obj, member, getter) => {
444
- __accessCheck$6(obj, member, "read from private field");
450
+ var __privateGet$6 = (obj, member, getter) => {
451
+ __accessCheck$7(obj, member, "read from private field");
445
452
  return getter ? getter.call(obj) : member.get(obj);
446
453
  };
447
- var __privateAdd$6 = (obj, member, value) => {
454
+ var __privateAdd$7 = (obj, member, value) => {
448
455
  if (member.has(obj))
449
456
  throw TypeError("Cannot add the same private member more than once");
450
457
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
451
458
  };
452
- var __privateSet$4 = (obj, member, value, setter) => {
453
- __accessCheck$6(obj, member, "write to private field");
459
+ var __privateSet$5 = (obj, member, value, setter) => {
460
+ __accessCheck$7(obj, member, "write to private field");
454
461
  setter ? setter.call(obj, value) : member.set(obj, value);
455
462
  return value;
456
463
  };
457
464
  var _extraProps, _namespaces;
458
465
  class XataApiClient {
459
466
  constructor(options = {}) {
460
- __privateAdd$6(this, _extraProps, void 0);
461
- __privateAdd$6(this, _namespaces, {});
467
+ __privateAdd$7(this, _extraProps, void 0);
468
+ __privateAdd$7(this, _namespaces, {});
462
469
  const provider = options.host ?? "production";
463
470
  const apiKey = options?.apiKey ?? getAPIKey();
464
471
  if (!apiKey) {
465
472
  throw new Error("Could not resolve a valid apiKey");
466
473
  }
467
- __privateSet$4(this, _extraProps, {
474
+ __privateSet$5(this, _extraProps, {
468
475
  apiUrl: getHostUrl(provider, "main"),
469
476
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
470
477
  fetchImpl: getFetchImplementation(options.fetch),
@@ -472,34 +479,34 @@ class XataApiClient {
472
479
  });
473
480
  }
474
481
  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;
482
+ if (!__privateGet$6(this, _namespaces).user)
483
+ __privateGet$6(this, _namespaces).user = new UserApi(__privateGet$6(this, _extraProps));
484
+ return __privateGet$6(this, _namespaces).user;
478
485
  }
479
486
  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;
487
+ if (!__privateGet$6(this, _namespaces).workspaces)
488
+ __privateGet$6(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$6(this, _extraProps));
489
+ return __privateGet$6(this, _namespaces).workspaces;
483
490
  }
484
491
  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;
492
+ if (!__privateGet$6(this, _namespaces).databases)
493
+ __privateGet$6(this, _namespaces).databases = new DatabaseApi(__privateGet$6(this, _extraProps));
494
+ return __privateGet$6(this, _namespaces).databases;
488
495
  }
489
496
  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;
497
+ if (!__privateGet$6(this, _namespaces).branches)
498
+ __privateGet$6(this, _namespaces).branches = new BranchApi(__privateGet$6(this, _extraProps));
499
+ return __privateGet$6(this, _namespaces).branches;
493
500
  }
494
501
  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;
502
+ if (!__privateGet$6(this, _namespaces).tables)
503
+ __privateGet$6(this, _namespaces).tables = new TableApi(__privateGet$6(this, _extraProps));
504
+ return __privateGet$6(this, _namespaces).tables;
498
505
  }
499
506
  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;
507
+ if (!__privateGet$6(this, _namespaces).records)
508
+ __privateGet$6(this, _namespaces).records = new RecordsApi(__privateGet$6(this, _extraProps));
509
+ return __privateGet$6(this, _namespaces).records;
503
510
  }
504
511
  }
505
512
  _extraProps = new WeakMap();
@@ -854,43 +861,43 @@ class XataApiPlugin {
854
861
  class XataPlugin {
855
862
  }
856
863
 
857
- var __accessCheck$5 = (obj, member, msg) => {
864
+ var __accessCheck$6 = (obj, member, msg) => {
858
865
  if (!member.has(obj))
859
866
  throw TypeError("Cannot " + msg);
860
867
  };
861
- var __privateGet$4 = (obj, member, getter) => {
862
- __accessCheck$5(obj, member, "read from private field");
868
+ var __privateGet$5 = (obj, member, getter) => {
869
+ __accessCheck$6(obj, member, "read from private field");
863
870
  return getter ? getter.call(obj) : member.get(obj);
864
871
  };
865
- var __privateAdd$5 = (obj, member, value) => {
872
+ var __privateAdd$6 = (obj, member, value) => {
866
873
  if (member.has(obj))
867
874
  throw TypeError("Cannot add the same private member more than once");
868
875
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
869
876
  };
870
- var __privateSet$3 = (obj, member, value, setter) => {
871
- __accessCheck$5(obj, member, "write to private field");
877
+ var __privateSet$4 = (obj, member, value, setter) => {
878
+ __accessCheck$6(obj, member, "write to private field");
872
879
  setter ? setter.call(obj, value) : member.set(obj, value);
873
880
  return value;
874
881
  };
875
882
  var _query;
876
883
  class Page {
877
884
  constructor(query, meta, records = []) {
878
- __privateAdd$5(this, _query, void 0);
879
- __privateSet$3(this, _query, query);
885
+ __privateAdd$6(this, _query, void 0);
886
+ __privateSet$4(this, _query, query);
880
887
  this.meta = meta;
881
888
  this.records = records;
882
889
  }
883
890
  async nextPage(size, offset) {
884
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
891
+ return __privateGet$5(this, _query).getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
885
892
  }
886
893
  async previousPage(size, offset) {
887
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
894
+ return __privateGet$5(this, _query).getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
888
895
  }
889
896
  async firstPage(size, offset) {
890
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
897
+ return __privateGet$5(this, _query).getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
891
898
  }
892
899
  async lastPage(size, offset) {
893
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
900
+ return __privateGet$5(this, _query).getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
894
901
  }
895
902
  hasNextPage() {
896
903
  return this.meta.page.more;
@@ -902,46 +909,47 @@ const PAGINATION_DEFAULT_SIZE = 200;
902
909
  const PAGINATION_MAX_OFFSET = 800;
903
910
  const PAGINATION_DEFAULT_OFFSET = 0;
904
911
 
905
- var __accessCheck$4 = (obj, member, msg) => {
912
+ var __accessCheck$5 = (obj, member, msg) => {
906
913
  if (!member.has(obj))
907
914
  throw TypeError("Cannot " + msg);
908
915
  };
909
- var __privateGet$3 = (obj, member, getter) => {
910
- __accessCheck$4(obj, member, "read from private field");
916
+ var __privateGet$4 = (obj, member, getter) => {
917
+ __accessCheck$5(obj, member, "read from private field");
911
918
  return getter ? getter.call(obj) : member.get(obj);
912
919
  };
913
- var __privateAdd$4 = (obj, member, value) => {
920
+ var __privateAdd$5 = (obj, member, value) => {
914
921
  if (member.has(obj))
915
922
  throw TypeError("Cannot add the same private member more than once");
916
923
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
917
924
  };
918
- var __privateSet$2 = (obj, member, value, setter) => {
919
- __accessCheck$4(obj, member, "write to private field");
925
+ var __privateSet$3 = (obj, member, value, setter) => {
926
+ __accessCheck$5(obj, member, "write to private field");
920
927
  setter ? setter.call(obj, value) : member.set(obj, value);
921
928
  return value;
922
929
  };
923
930
  var _table$1, _repository, _data;
924
931
  const _Query = class {
925
932
  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: {} });
933
+ __privateAdd$5(this, _table$1, void 0);
934
+ __privateAdd$5(this, _repository, void 0);
935
+ __privateAdd$5(this, _data, { filter: {} });
929
936
  this.meta = { page: { cursor: "start", more: true } };
930
937
  this.records = [];
931
- __privateSet$2(this, _table$1, table);
938
+ __privateSet$3(this, _table$1, table);
932
939
  if (repository) {
933
- __privateSet$2(this, _repository, repository);
940
+ __privateSet$3(this, _repository, repository);
934
941
  } else {
935
- __privateSet$2(this, _repository, this);
942
+ __privateSet$3(this, _repository, this);
936
943
  }
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;
944
+ __privateGet$4(this, _data).filter = data.filter ?? parent?.filter ?? {};
945
+ __privateGet$4(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
946
+ __privateGet$4(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
947
+ __privateGet$4(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
948
+ __privateGet$4(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
949
+ __privateGet$4(this, _data).sort = data.sort ?? parent?.sort;
950
+ __privateGet$4(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
951
+ __privateGet$4(this, _data).page = data.page ?? parent?.page;
952
+ __privateGet$4(this, _data).cache = data.cache ?? parent?.cache;
945
953
  this.any = this.any.bind(this);
946
954
  this.all = this.all.bind(this);
947
955
  this.not = this.not.bind(this);
@@ -952,45 +960,50 @@ const _Query = class {
952
960
  Object.defineProperty(this, "repository", { enumerable: false });
953
961
  }
954
962
  getQueryOptions() {
955
- return __privateGet$3(this, _data);
963
+ return __privateGet$4(this, _data);
964
+ }
965
+ key() {
966
+ const { columns = [], filter = {}, sort = [], page = {} } = __privateGet$4(this, _data);
967
+ const key = JSON.stringify({ columns, filter, sort, page });
968
+ return toBase64(key);
956
969
  }
957
970
  any(...queries) {
958
971
  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));
972
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $any } }, __privateGet$4(this, _data));
960
973
  }
961
974
  all(...queries) {
962
975
  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));
976
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
964
977
  }
965
978
  not(...queries) {
966
979
  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));
980
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $not } }, __privateGet$4(this, _data));
968
981
  }
969
982
  none(...queries) {
970
983
  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));
984
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $none } }, __privateGet$4(this, _data));
972
985
  }
973
986
  filter(a, b) {
974
987
  if (arguments.length === 1) {
975
988
  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));
989
+ const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat(constraints));
990
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
978
991
  } 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));
992
+ const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
993
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
981
994
  }
982
995
  }
983
996
  sort(column, direction) {
984
- const originalSort = [__privateGet$3(this, _data).sort ?? []].flat();
997
+ const originalSort = [__privateGet$4(this, _data).sort ?? []].flat();
985
998
  const sort = [...originalSort, { column, direction }];
986
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { sort }, __privateGet$3(this, _data));
999
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { sort }, __privateGet$4(this, _data));
987
1000
  }
988
1001
  select(columns) {
989
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { columns }, __privateGet$3(this, _data));
1002
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { columns }, __privateGet$4(this, _data));
990
1003
  }
991
1004
  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);
1005
+ const query = new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), options, __privateGet$4(this, _data));
1006
+ return __privateGet$4(this, _repository).query(query);
994
1007
  }
995
1008
  async *[Symbol.asyncIterator]() {
996
1009
  for await (const [record] of this.getIterator(1)) {
@@ -1018,10 +1031,13 @@ const _Query = class {
1018
1031
  }
1019
1032
  return results;
1020
1033
  }
1021
- async getOne(options = {}) {
1034
+ async getFirst(options = {}) {
1022
1035
  const records = await this.getMany({ ...options, page: { size: 1 } });
1023
1036
  return records[0] || null;
1024
1037
  }
1038
+ cache(ttl) {
1039
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { cache: ttl }, __privateGet$4(this, _data));
1040
+ }
1025
1041
  nextPage(size, offset) {
1026
1042
  return this.firstPage(size, offset);
1027
1043
  }
@@ -1073,75 +1089,93 @@ function buildSortFilter(filter) {
1073
1089
  }
1074
1090
  }
1075
1091
 
1076
- var __accessCheck$3 = (obj, member, msg) => {
1092
+ var __accessCheck$4 = (obj, member, msg) => {
1077
1093
  if (!member.has(obj))
1078
1094
  throw TypeError("Cannot " + msg);
1079
1095
  };
1080
- var __privateGet$2 = (obj, member, getter) => {
1081
- __accessCheck$3(obj, member, "read from private field");
1096
+ var __privateGet$3 = (obj, member, getter) => {
1097
+ __accessCheck$4(obj, member, "read from private field");
1082
1098
  return getter ? getter.call(obj) : member.get(obj);
1083
1099
  };
1084
- var __privateAdd$3 = (obj, member, value) => {
1100
+ var __privateAdd$4 = (obj, member, value) => {
1085
1101
  if (member.has(obj))
1086
1102
  throw TypeError("Cannot add the same private member more than once");
1087
1103
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1088
1104
  };
1089
- var __privateSet$1 = (obj, member, value, setter) => {
1090
- __accessCheck$3(obj, member, "write to private field");
1105
+ var __privateSet$2 = (obj, member, value, setter) => {
1106
+ __accessCheck$4(obj, member, "write to private field");
1091
1107
  setter ? setter.call(obj, value) : member.set(obj, value);
1092
1108
  return value;
1093
1109
  };
1094
1110
  var __privateMethod$2 = (obj, member, method) => {
1095
- __accessCheck$3(obj, member, "access private method");
1111
+ __accessCheck$4(obj, member, "access private method");
1096
1112
  return method;
1097
1113
  };
1098
- var _table, _links, _getFetchProps, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn;
1114
+ 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
1115
  class Repository extends Query {
1100
1116
  }
1101
1117
  class RestRepository extends Query {
1102
1118
  constructor(options) {
1103
1119
  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);
1120
+ __privateAdd$4(this, _insertRecordWithoutId);
1121
+ __privateAdd$4(this, _insertRecordWithId);
1122
+ __privateAdd$4(this, _bulkInsertTableRecords);
1123
+ __privateAdd$4(this, _updateRecordWithID);
1124
+ __privateAdd$4(this, _upsertRecordWithID);
1125
+ __privateAdd$4(this, _deleteRecord);
1126
+ __privateAdd$4(this, _invalidateCache);
1127
+ __privateAdd$4(this, _setCacheRecord);
1128
+ __privateAdd$4(this, _getCacheRecord);
1129
+ __privateAdd$4(this, _setCacheQuery);
1130
+ __privateAdd$4(this, _getCacheQuery);
1131
+ __privateAdd$4(this, _table, void 0);
1132
+ __privateAdd$4(this, _links, void 0);
1133
+ __privateAdd$4(this, _getFetchProps, void 0);
1134
+ __privateAdd$4(this, _cache, void 0);
1135
+ __privateSet$2(this, _table, options.table);
1136
+ __privateSet$2(this, _links, options.links ?? {});
1137
+ __privateSet$2(this, _getFetchProps, options.pluginOptions.getFetchProps);
1116
1138
  this.db = options.db;
1139
+ __privateSet$2(this, _cache, options.pluginOptions.cache);
1117
1140
  }
1118
1141
  async create(a, b) {
1119
1142
  if (Array.isArray(a)) {
1120
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1143
+ const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1144
+ await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1145
+ return records;
1121
1146
  }
1122
1147
  if (isString(a) && isObject(b)) {
1123
1148
  if (a === "")
1124
1149
  throw new Error("The id can't be empty");
1125
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1150
+ const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1151
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1152
+ return record;
1126
1153
  }
1127
1154
  if (isObject(a) && isString(a.id)) {
1128
1155
  if (a.id === "")
1129
1156
  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 });
1157
+ const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1158
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1159
+ return record;
1131
1160
  }
1132
1161
  if (isObject(a)) {
1133
- return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1162
+ const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1163
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1164
+ return record;
1134
1165
  }
1135
1166
  throw new Error("Invalid arguments for create method");
1136
1167
  }
1137
1168
  async read(recordId) {
1138
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1169
+ const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, recordId);
1170
+ if (cacheRecord)
1171
+ return cacheRecord;
1172
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1139
1173
  try {
1140
1174
  const response = await getRecord({
1141
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1175
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1142
1176
  ...fetchProps
1143
1177
  });
1144
- return initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), response);
1178
+ return initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), response);
1145
1179
  } catch (e) {
1146
1180
  if (isObject(e) && e.status === 404) {
1147
1181
  return null;
@@ -1157,10 +1191,16 @@ class RestRepository extends Query {
1157
1191
  return Promise.all(a.map((object) => this.update(object)));
1158
1192
  }
1159
1193
  if (isString(a) && isObject(b)) {
1160
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1194
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1195
+ const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1196
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1197
+ return record;
1161
1198
  }
1162
1199
  if (isObject(a) && isString(a.id)) {
1163
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1200
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1201
+ const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1202
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1203
+ return record;
1164
1204
  }
1165
1205
  throw new Error("Invalid arguments for update method");
1166
1206
  }
@@ -1172,41 +1212,52 @@ class RestRepository extends Query {
1172
1212
  return Promise.all(a.map((object) => this.createOrUpdate(object)));
1173
1213
  }
1174
1214
  if (isString(a) && isObject(b)) {
1175
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1215
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1216
+ const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1217
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1218
+ return record;
1176
1219
  }
1177
1220
  if (isObject(a) && isString(a.id)) {
1178
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1221
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1222
+ const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1223
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1224
+ return record;
1179
1225
  }
1180
1226
  throw new Error("Invalid arguments for createOrUpdate method");
1181
1227
  }
1182
- async delete(recordId) {
1183
- if (Array.isArray(recordId)) {
1184
- if (recordId.length > 100) {
1228
+ async delete(a) {
1229
+ if (Array.isArray(a)) {
1230
+ if (a.length > 100) {
1185
1231
  console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1186
1232
  }
1187
- await Promise.all(recordId.map((id) => this.delete(id)));
1233
+ await Promise.all(a.map((id) => this.delete(id)));
1188
1234
  return;
1189
1235
  }
1190
- if (isString(recordId)) {
1191
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, recordId);
1236
+ if (isString(a)) {
1237
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1238
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1192
1239
  return;
1193
1240
  }
1194
- if (isObject(recordId) && isString(recordId.id)) {
1195
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, recordId.id);
1241
+ if (isObject(a) && isString(a.id)) {
1242
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1243
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1196
1244
  return;
1197
1245
  }
1198
1246
  throw new Error("Invalid arguments for delete method");
1199
1247
  }
1200
1248
  async search(query, options = {}) {
1201
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1249
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1202
1250
  const { records } = await searchBranch({
1203
1251
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1204
- body: { tables: [__privateGet$2(this, _table)], query, fuzziness: options.fuzziness },
1252
+ body: { tables: [__privateGet$3(this, _table)], query, fuzziness: options.fuzziness },
1205
1253
  ...fetchProps
1206
1254
  });
1207
- return records.map((item) => initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), item));
1255
+ return records.map((item) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), item));
1208
1256
  }
1209
1257
  async query(query) {
1258
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1259
+ if (cacheQuery)
1260
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
1210
1261
  const data = query.getQueryOptions();
1211
1262
  const body = {
1212
1263
  filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
@@ -1214,28 +1265,30 @@ class RestRepository extends Query {
1214
1265
  page: data.page,
1215
1266
  columns: data.columns
1216
1267
  };
1217
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1268
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1218
1269
  const { meta, records: objects } = await queryTable({
1219
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table) },
1270
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
1220
1271
  body,
1221
1272
  ...fetchProps
1222
1273
  });
1223
- const records = objects.map((record) => initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), record));
1274
+ const records = objects.map((record) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), record));
1275
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1224
1276
  return new Page(query, meta, records);
1225
1277
  }
1226
1278
  }
1227
1279
  _table = new WeakMap();
1228
1280
  _links = new WeakMap();
1229
1281
  _getFetchProps = new WeakMap();
1282
+ _cache = new WeakMap();
1230
1283
  _insertRecordWithoutId = new WeakSet();
1231
1284
  insertRecordWithoutId_fn = async function(object) {
1232
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1285
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1233
1286
  const record = transformObjectLinks(object);
1234
1287
  const response = await insertRecord({
1235
1288
  pathParams: {
1236
1289
  workspace: "{workspaceId}",
1237
1290
  dbBranchName: "{dbBranch}",
1238
- tableName: __privateGet$2(this, _table)
1291
+ tableName: __privateGet$3(this, _table)
1239
1292
  },
1240
1293
  body: record,
1241
1294
  ...fetchProps
@@ -1248,13 +1301,13 @@ insertRecordWithoutId_fn = async function(object) {
1248
1301
  };
1249
1302
  _insertRecordWithId = new WeakSet();
1250
1303
  insertRecordWithId_fn = async function(recordId, object) {
1251
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1304
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1252
1305
  const record = transformObjectLinks(object);
1253
1306
  const response = await insertRecordWithID({
1254
1307
  pathParams: {
1255
1308
  workspace: "{workspaceId}",
1256
1309
  dbBranchName: "{dbBranch}",
1257
- tableName: __privateGet$2(this, _table),
1310
+ tableName: __privateGet$3(this, _table),
1258
1311
  recordId
1259
1312
  },
1260
1313
  body: record,
@@ -1269,10 +1322,10 @@ insertRecordWithId_fn = async function(recordId, object) {
1269
1322
  };
1270
1323
  _bulkInsertTableRecords = new WeakSet();
1271
1324
  bulkInsertTableRecords_fn = async function(objects) {
1272
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1325
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1273
1326
  const records = objects.map((object) => transformObjectLinks(object));
1274
1327
  const response = await bulkInsertTableRecords({
1275
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table) },
1328
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
1276
1329
  body: { records },
1277
1330
  ...fetchProps
1278
1331
  });
@@ -1284,10 +1337,10 @@ bulkInsertTableRecords_fn = async function(objects) {
1284
1337
  };
1285
1338
  _updateRecordWithID = new WeakSet();
1286
1339
  updateRecordWithID_fn = async function(recordId, object) {
1287
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1340
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1288
1341
  const record = transformObjectLinks(object);
1289
1342
  const response = await updateRecordWithID({
1290
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1343
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1291
1344
  body: record,
1292
1345
  ...fetchProps
1293
1346
  });
@@ -1298,9 +1351,9 @@ updateRecordWithID_fn = async function(recordId, object) {
1298
1351
  };
1299
1352
  _upsertRecordWithID = new WeakSet();
1300
1353
  upsertRecordWithID_fn = async function(recordId, object) {
1301
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1354
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1302
1355
  const response = await upsertRecordWithID({
1303
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1356
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1304
1357
  body: object,
1305
1358
  ...fetchProps
1306
1359
  });
@@ -1311,12 +1364,51 @@ upsertRecordWithID_fn = async function(recordId, object) {
1311
1364
  };
1312
1365
  _deleteRecord = new WeakSet();
1313
1366
  deleteRecord_fn = async function(recordId) {
1314
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1367
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1315
1368
  await deleteRecord({
1316
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1369
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1317
1370
  ...fetchProps
1318
1371
  });
1319
1372
  };
1373
+ _invalidateCache = new WeakSet();
1374
+ invalidateCache_fn = async function(recordId) {
1375
+ await __privateGet$3(this, _cache).delete(`rec_${__privateGet$3(this, _table)}:${recordId}`);
1376
+ const cacheItems = await __privateGet$3(this, _cache).getAll();
1377
+ const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1378
+ for (const [key, value] of queries) {
1379
+ const ids = getIds(value);
1380
+ if (ids.includes(recordId))
1381
+ await __privateGet$3(this, _cache).delete(key);
1382
+ }
1383
+ };
1384
+ _setCacheRecord = new WeakSet();
1385
+ setCacheRecord_fn = async function(record) {
1386
+ if (!__privateGet$3(this, _cache).cacheRecords)
1387
+ return;
1388
+ await __privateGet$3(this, _cache).set(`rec_${__privateGet$3(this, _table)}:${record.id}`, record);
1389
+ };
1390
+ _getCacheRecord = new WeakSet();
1391
+ getCacheRecord_fn = async function(recordId) {
1392
+ if (!__privateGet$3(this, _cache).cacheRecords)
1393
+ return null;
1394
+ return __privateGet$3(this, _cache).get(`rec_${__privateGet$3(this, _table)}:${recordId}`);
1395
+ };
1396
+ _setCacheQuery = new WeakSet();
1397
+ setCacheQuery_fn = async function(query, meta, records) {
1398
+ await __privateGet$3(this, _cache).set(`query_${__privateGet$3(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
1399
+ };
1400
+ _getCacheQuery = new WeakSet();
1401
+ getCacheQuery_fn = async function(query) {
1402
+ const key = `query_${__privateGet$3(this, _table)}:${query.key()}`;
1403
+ const result = await __privateGet$3(this, _cache).get(key);
1404
+ if (!result)
1405
+ return null;
1406
+ const { cache: ttl = __privateGet$3(this, _cache).defaultQueryTTL } = query.getQueryOptions();
1407
+ if (!ttl || ttl < 0)
1408
+ return result;
1409
+ const hasExpired = result.date.getTime() + ttl < Date.now();
1410
+ return hasExpired ? null : result;
1411
+ };
1320
1412
  const transformObjectLinks = (object) => {
1321
1413
  return Object.entries(object).reduce((acc, [key, value]) => {
1322
1414
  if (key === "xata")
@@ -1350,6 +1442,65 @@ const initObject = (db, links, table, object) => {
1350
1442
  Object.freeze(result);
1351
1443
  return result;
1352
1444
  };
1445
+ function getIds(value) {
1446
+ if (Array.isArray(value)) {
1447
+ return value.map((item) => getIds(item)).flat();
1448
+ }
1449
+ if (!isObject(value))
1450
+ return [];
1451
+ const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1452
+ return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
1453
+ }
1454
+
1455
+ var __accessCheck$3 = (obj, member, msg) => {
1456
+ if (!member.has(obj))
1457
+ throw TypeError("Cannot " + msg);
1458
+ };
1459
+ var __privateGet$2 = (obj, member, getter) => {
1460
+ __accessCheck$3(obj, member, "read from private field");
1461
+ return getter ? getter.call(obj) : member.get(obj);
1462
+ };
1463
+ var __privateAdd$3 = (obj, member, value) => {
1464
+ if (member.has(obj))
1465
+ throw TypeError("Cannot add the same private member more than once");
1466
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1467
+ };
1468
+ var __privateSet$1 = (obj, member, value, setter) => {
1469
+ __accessCheck$3(obj, member, "write to private field");
1470
+ setter ? setter.call(obj, value) : member.set(obj, value);
1471
+ return value;
1472
+ };
1473
+ var _map;
1474
+ class SimpleCache {
1475
+ constructor(options = {}) {
1476
+ __privateAdd$3(this, _map, void 0);
1477
+ __privateSet$1(this, _map, /* @__PURE__ */ new Map());
1478
+ this.capacity = options.max ?? 500;
1479
+ this.cacheRecords = options.cacheRecords ?? true;
1480
+ this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1481
+ }
1482
+ async getAll() {
1483
+ return Object.fromEntries(__privateGet$2(this, _map));
1484
+ }
1485
+ async get(key) {
1486
+ return __privateGet$2(this, _map).get(key) ?? null;
1487
+ }
1488
+ async set(key, value) {
1489
+ await this.delete(key);
1490
+ __privateGet$2(this, _map).set(key, value);
1491
+ if (__privateGet$2(this, _map).size > this.capacity) {
1492
+ const leastRecentlyUsed = __privateGet$2(this, _map).keys().next().value;
1493
+ await this.delete(leastRecentlyUsed);
1494
+ }
1495
+ }
1496
+ async delete(key) {
1497
+ __privateGet$2(this, _map).delete(key);
1498
+ }
1499
+ async clear() {
1500
+ return __privateGet$2(this, _map).clear();
1501
+ }
1502
+ }
1503
+ _map = new WeakMap();
1353
1504
 
1354
1505
  const gt = (value) => ({ $gt: value });
1355
1506
  const ge = (value) => ({ $ge: value });
@@ -1385,23 +1536,27 @@ var __privateAdd$2 = (obj, member, value) => {
1385
1536
  };
1386
1537
  var _tables;
1387
1538
  class SchemaPlugin extends XataPlugin {
1388
- constructor(links) {
1539
+ constructor(links, tableNames) {
1389
1540
  super();
1390
1541
  this.links = links;
1542
+ this.tableNames = tableNames;
1391
1543
  __privateAdd$2(this, _tables, {});
1392
1544
  }
1393
- build(options) {
1394
- const { getFetchProps } = options;
1545
+ build(pluginOptions) {
1395
1546
  const links = this.links;
1396
1547
  const db = new Proxy({}, {
1397
1548
  get: (_target, table) => {
1398
1549
  if (!isString(table))
1399
1550
  throw new Error("Invalid table name");
1400
- if (!__privateGet$1(this, _tables)[table])
1401
- __privateGet$1(this, _tables)[table] = new RestRepository({ db, getFetchProps, table, links });
1551
+ if (!__privateGet$1(this, _tables)[table]) {
1552
+ __privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, links });
1553
+ }
1402
1554
  return __privateGet$1(this, _tables)[table];
1403
1555
  }
1404
1556
  });
1557
+ for (const table of this.tableNames ?? []) {
1558
+ db[table] = new RestRepository({ db, pluginOptions, table, links });
1559
+ }
1405
1560
  return db;
1406
1561
  }
1407
1562
  }
@@ -1568,22 +1723,24 @@ var __privateMethod = (obj, member, method) => {
1568
1723
  const buildClient = (plugins) => {
1569
1724
  var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
1570
1725
  return _a = class {
1571
- constructor(options = {}, links) {
1726
+ constructor(options = {}, links, tables) {
1572
1727
  __privateAdd(this, _parseOptions);
1573
1728
  __privateAdd(this, _getFetchProps);
1574
1729
  __privateAdd(this, _evaluateBranch);
1575
1730
  __privateAdd(this, _branch, void 0);
1576
1731
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
1577
- const db = new SchemaPlugin(links).build({ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions) });
1578
- const search = new SearchPlugin(db, links ?? {}).build({
1579
- getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions)
1580
- });
1732
+ const pluginOptions = {
1733
+ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
1734
+ cache: safeOptions.cache
1735
+ };
1736
+ const db = new SchemaPlugin(links, tables).build(pluginOptions);
1737
+ const search = new SearchPlugin(db, links ?? {}).build(pluginOptions);
1581
1738
  this.db = db;
1582
1739
  this.search = search;
1583
1740
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
1584
1741
  if (!namespace)
1585
1742
  continue;
1586
- const result = namespace.build({ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions) });
1743
+ const result = namespace.build(pluginOptions);
1587
1744
  if (result instanceof Promise) {
1588
1745
  void result.then((namespace2) => {
1589
1746
  this[key] = namespace2;
@@ -1597,11 +1754,12 @@ const buildClient = (plugins) => {
1597
1754
  const fetch = getFetchImplementation(options?.fetch);
1598
1755
  const databaseURL = options?.databaseURL || getDatabaseURL();
1599
1756
  const apiKey = options?.apiKey || getAPIKey();
1757
+ const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
1600
1758
  const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
1601
1759
  if (!databaseURL || !apiKey) {
1602
1760
  throw new Error("Options databaseURL and apiKey are required");
1603
1761
  }
1604
- return { fetch, databaseURL, apiKey, branch };
1762
+ return { fetch, databaseURL, apiKey, branch, cache };
1605
1763
  }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
1606
1764
  fetch,
1607
1765
  apiKey,
@@ -1661,6 +1819,7 @@ exports.Repository = Repository;
1661
1819
  exports.RestRepository = RestRepository;
1662
1820
  exports.SchemaPlugin = SchemaPlugin;
1663
1821
  exports.SearchPlugin = SearchPlugin;
1822
+ exports.SimpleCache = SimpleCache;
1664
1823
  exports.XataApiClient = XataApiClient;
1665
1824
  exports.XataApiPlugin = XataApiPlugin;
1666
1825
  exports.XataError = XataError;