@xata.io/client 0.0.0-alpha.vf89b33e → 0.0.0-alpha.vfd071d9

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 {
@@ -31,7 +38,10 @@ function getEnvVariable(name) {
31
38
  }
32
39
  async function getGitBranch() {
33
40
  try {
34
- return require("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
41
+ if (typeof require === "function") {
42
+ const req = require;
43
+ return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
44
+ }
35
45
  } catch (err) {
36
46
  }
37
47
  try {
@@ -245,6 +255,14 @@ const deleteDatabase = (variables) => fetch$1({
245
255
  method: "delete",
246
256
  ...variables
247
257
  });
258
+ const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
259
+ const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
260
+ const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
261
+ const resolveBranch = (variables) => fetch$1({
262
+ url: "/dbs/{dbName}/resolveBranch",
263
+ method: "get",
264
+ ...variables
265
+ });
248
266
  const getBranchDetails = (variables) => fetch$1({
249
267
  url: "/db/{dbBranchName}",
250
268
  method: "get",
@@ -373,7 +391,15 @@ const operationsByTag = {
373
391
  resendWorkspaceMemberInvite,
374
392
  acceptWorkspaceMemberInvite
375
393
  },
376
- database: { getDatabaseList, createDatabase, deleteDatabase },
394
+ database: {
395
+ getDatabaseList,
396
+ createDatabase,
397
+ deleteDatabase,
398
+ getGitBranchesMapping,
399
+ addGitBranchesEntry,
400
+ removeGitBranchesEntry,
401
+ resolveBranch
402
+ },
377
403
  branch: {
378
404
  getBranchList,
379
405
  getBranchDetails,
@@ -436,35 +462,35 @@ function isValidBuilder(builder) {
436
462
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
437
463
  }
438
464
 
439
- var __accessCheck$6 = (obj, member, msg) => {
465
+ var __accessCheck$7 = (obj, member, msg) => {
440
466
  if (!member.has(obj))
441
467
  throw TypeError("Cannot " + msg);
442
468
  };
443
- var __privateGet$5 = (obj, member, getter) => {
444
- __accessCheck$6(obj, member, "read from private field");
469
+ var __privateGet$6 = (obj, member, getter) => {
470
+ __accessCheck$7(obj, member, "read from private field");
445
471
  return getter ? getter.call(obj) : member.get(obj);
446
472
  };
447
- var __privateAdd$6 = (obj, member, value) => {
473
+ var __privateAdd$7 = (obj, member, value) => {
448
474
  if (member.has(obj))
449
475
  throw TypeError("Cannot add the same private member more than once");
450
476
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
451
477
  };
452
- var __privateSet$4 = (obj, member, value, setter) => {
453
- __accessCheck$6(obj, member, "write to private field");
478
+ var __privateSet$5 = (obj, member, value, setter) => {
479
+ __accessCheck$7(obj, member, "write to private field");
454
480
  setter ? setter.call(obj, value) : member.set(obj, value);
455
481
  return value;
456
482
  };
457
483
  var _extraProps, _namespaces;
458
484
  class XataApiClient {
459
485
  constructor(options = {}) {
460
- __privateAdd$6(this, _extraProps, void 0);
461
- __privateAdd$6(this, _namespaces, {});
486
+ __privateAdd$7(this, _extraProps, void 0);
487
+ __privateAdd$7(this, _namespaces, {});
462
488
  const provider = options.host ?? "production";
463
489
  const apiKey = options?.apiKey ?? getAPIKey();
464
490
  if (!apiKey) {
465
491
  throw new Error("Could not resolve a valid apiKey");
466
492
  }
467
- __privateSet$4(this, _extraProps, {
493
+ __privateSet$5(this, _extraProps, {
468
494
  apiUrl: getHostUrl(provider, "main"),
469
495
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
470
496
  fetchImpl: getFetchImplementation(options.fetch),
@@ -472,34 +498,34 @@ class XataApiClient {
472
498
  });
473
499
  }
474
500
  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;
501
+ if (!__privateGet$6(this, _namespaces).user)
502
+ __privateGet$6(this, _namespaces).user = new UserApi(__privateGet$6(this, _extraProps));
503
+ return __privateGet$6(this, _namespaces).user;
478
504
  }
479
505
  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;
506
+ if (!__privateGet$6(this, _namespaces).workspaces)
507
+ __privateGet$6(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$6(this, _extraProps));
508
+ return __privateGet$6(this, _namespaces).workspaces;
483
509
  }
484
510
  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;
511
+ if (!__privateGet$6(this, _namespaces).databases)
512
+ __privateGet$6(this, _namespaces).databases = new DatabaseApi(__privateGet$6(this, _extraProps));
513
+ return __privateGet$6(this, _namespaces).databases;
488
514
  }
489
515
  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;
516
+ if (!__privateGet$6(this, _namespaces).branches)
517
+ __privateGet$6(this, _namespaces).branches = new BranchApi(__privateGet$6(this, _extraProps));
518
+ return __privateGet$6(this, _namespaces).branches;
493
519
  }
494
520
  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;
521
+ if (!__privateGet$6(this, _namespaces).tables)
522
+ __privateGet$6(this, _namespaces).tables = new TableApi(__privateGet$6(this, _extraProps));
523
+ return __privateGet$6(this, _namespaces).tables;
498
524
  }
499
525
  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;
526
+ if (!__privateGet$6(this, _namespaces).records)
527
+ __privateGet$6(this, _namespaces).records = new RecordsApi(__privateGet$6(this, _extraProps));
528
+ return __privateGet$6(this, _namespaces).records;
503
529
  }
504
530
  }
505
531
  _extraProps = new WeakMap();
@@ -633,6 +659,33 @@ class DatabaseApi {
633
659
  ...this.extraProps
634
660
  });
635
661
  }
662
+ getGitBranchesMapping(workspace, dbName) {
663
+ return operationsByTag.database.getGitBranchesMapping({
664
+ pathParams: { workspace, dbName },
665
+ ...this.extraProps
666
+ });
667
+ }
668
+ addGitBranchesEntry(workspace, dbName, body) {
669
+ return operationsByTag.database.addGitBranchesEntry({
670
+ pathParams: { workspace, dbName },
671
+ body,
672
+ ...this.extraProps
673
+ });
674
+ }
675
+ removeGitBranchesEntry(workspace, dbName, gitBranch) {
676
+ return operationsByTag.database.removeGitBranchesEntry({
677
+ pathParams: { workspace, dbName },
678
+ queryParams: { gitBranch },
679
+ ...this.extraProps
680
+ });
681
+ }
682
+ resolveBranch(workspace, dbName, gitBranch) {
683
+ return operationsByTag.database.resolveBranch({
684
+ pathParams: { workspace, dbName },
685
+ queryParams: { gitBranch },
686
+ ...this.extraProps
687
+ });
688
+ }
636
689
  }
637
690
  class BranchApi {
638
691
  constructor(extraProps) {
@@ -854,43 +907,43 @@ class XataApiPlugin {
854
907
  class XataPlugin {
855
908
  }
856
909
 
857
- var __accessCheck$5 = (obj, member, msg) => {
910
+ var __accessCheck$6 = (obj, member, msg) => {
858
911
  if (!member.has(obj))
859
912
  throw TypeError("Cannot " + msg);
860
913
  };
861
- var __privateGet$4 = (obj, member, getter) => {
862
- __accessCheck$5(obj, member, "read from private field");
914
+ var __privateGet$5 = (obj, member, getter) => {
915
+ __accessCheck$6(obj, member, "read from private field");
863
916
  return getter ? getter.call(obj) : member.get(obj);
864
917
  };
865
- var __privateAdd$5 = (obj, member, value) => {
918
+ var __privateAdd$6 = (obj, member, value) => {
866
919
  if (member.has(obj))
867
920
  throw TypeError("Cannot add the same private member more than once");
868
921
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
869
922
  };
870
- var __privateSet$3 = (obj, member, value, setter) => {
871
- __accessCheck$5(obj, member, "write to private field");
923
+ var __privateSet$4 = (obj, member, value, setter) => {
924
+ __accessCheck$6(obj, member, "write to private field");
872
925
  setter ? setter.call(obj, value) : member.set(obj, value);
873
926
  return value;
874
927
  };
875
928
  var _query;
876
929
  class Page {
877
930
  constructor(query, meta, records = []) {
878
- __privateAdd$5(this, _query, void 0);
879
- __privateSet$3(this, _query, query);
931
+ __privateAdd$6(this, _query, void 0);
932
+ __privateSet$4(this, _query, query);
880
933
  this.meta = meta;
881
934
  this.records = records;
882
935
  }
883
936
  async nextPage(size, offset) {
884
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
937
+ return __privateGet$5(this, _query).getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
885
938
  }
886
939
  async previousPage(size, offset) {
887
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
940
+ return __privateGet$5(this, _query).getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
888
941
  }
889
942
  async firstPage(size, offset) {
890
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
943
+ return __privateGet$5(this, _query).getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
891
944
  }
892
945
  async lastPage(size, offset) {
893
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
946
+ return __privateGet$5(this, _query).getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
894
947
  }
895
948
  hasNextPage() {
896
949
  return this.meta.page.more;
@@ -902,46 +955,47 @@ const PAGINATION_DEFAULT_SIZE = 200;
902
955
  const PAGINATION_MAX_OFFSET = 800;
903
956
  const PAGINATION_DEFAULT_OFFSET = 0;
904
957
 
905
- var __accessCheck$4 = (obj, member, msg) => {
958
+ var __accessCheck$5 = (obj, member, msg) => {
906
959
  if (!member.has(obj))
907
960
  throw TypeError("Cannot " + msg);
908
961
  };
909
- var __privateGet$3 = (obj, member, getter) => {
910
- __accessCheck$4(obj, member, "read from private field");
962
+ var __privateGet$4 = (obj, member, getter) => {
963
+ __accessCheck$5(obj, member, "read from private field");
911
964
  return getter ? getter.call(obj) : member.get(obj);
912
965
  };
913
- var __privateAdd$4 = (obj, member, value) => {
966
+ var __privateAdd$5 = (obj, member, value) => {
914
967
  if (member.has(obj))
915
968
  throw TypeError("Cannot add the same private member more than once");
916
969
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
917
970
  };
918
- var __privateSet$2 = (obj, member, value, setter) => {
919
- __accessCheck$4(obj, member, "write to private field");
971
+ var __privateSet$3 = (obj, member, value, setter) => {
972
+ __accessCheck$5(obj, member, "write to private field");
920
973
  setter ? setter.call(obj, value) : member.set(obj, value);
921
974
  return value;
922
975
  };
923
976
  var _table$1, _repository, _data;
924
977
  const _Query = class {
925
978
  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: {} });
979
+ __privateAdd$5(this, _table$1, void 0);
980
+ __privateAdd$5(this, _repository, void 0);
981
+ __privateAdd$5(this, _data, { filter: {} });
929
982
  this.meta = { page: { cursor: "start", more: true } };
930
983
  this.records = [];
931
- __privateSet$2(this, _table$1, table);
984
+ __privateSet$3(this, _table$1, table);
932
985
  if (repository) {
933
- __privateSet$2(this, _repository, repository);
986
+ __privateSet$3(this, _repository, repository);
934
987
  } else {
935
- __privateSet$2(this, _repository, this);
988
+ __privateSet$3(this, _repository, this);
936
989
  }
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;
990
+ __privateGet$4(this, _data).filter = data.filter ?? parent?.filter ?? {};
991
+ __privateGet$4(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
992
+ __privateGet$4(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
993
+ __privateGet$4(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
994
+ __privateGet$4(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
995
+ __privateGet$4(this, _data).sort = data.sort ?? parent?.sort;
996
+ __privateGet$4(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
997
+ __privateGet$4(this, _data).page = data.page ?? parent?.page;
998
+ __privateGet$4(this, _data).cache = data.cache ?? parent?.cache;
945
999
  this.any = this.any.bind(this);
946
1000
  this.all = this.all.bind(this);
947
1001
  this.not = this.not.bind(this);
@@ -952,45 +1006,50 @@ const _Query = class {
952
1006
  Object.defineProperty(this, "repository", { enumerable: false });
953
1007
  }
954
1008
  getQueryOptions() {
955
- return __privateGet$3(this, _data);
1009
+ return __privateGet$4(this, _data);
1010
+ }
1011
+ key() {
1012
+ const { columns = [], filter = {}, sort = [], page = {} } = __privateGet$4(this, _data);
1013
+ const key = JSON.stringify({ columns, filter, sort, page });
1014
+ return toBase64(key);
956
1015
  }
957
1016
  any(...queries) {
958
1017
  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));
1018
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $any } }, __privateGet$4(this, _data));
960
1019
  }
961
1020
  all(...queries) {
962
1021
  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));
1022
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
964
1023
  }
965
1024
  not(...queries) {
966
1025
  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));
1026
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $not } }, __privateGet$4(this, _data));
968
1027
  }
969
1028
  none(...queries) {
970
1029
  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));
1030
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $none } }, __privateGet$4(this, _data));
972
1031
  }
973
1032
  filter(a, b) {
974
1033
  if (arguments.length === 1) {
975
1034
  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));
1035
+ const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat(constraints));
1036
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
978
1037
  } 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));
1038
+ const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
1039
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
981
1040
  }
982
1041
  }
983
1042
  sort(column, direction) {
984
- const originalSort = [__privateGet$3(this, _data).sort ?? []].flat();
1043
+ const originalSort = [__privateGet$4(this, _data).sort ?? []].flat();
985
1044
  const sort = [...originalSort, { column, direction }];
986
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { sort }, __privateGet$3(this, _data));
1045
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { sort }, __privateGet$4(this, _data));
987
1046
  }
988
1047
  select(columns) {
989
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { columns }, __privateGet$3(this, _data));
1048
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { columns }, __privateGet$4(this, _data));
990
1049
  }
991
1050
  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);
1051
+ const query = new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), options, __privateGet$4(this, _data));
1052
+ return __privateGet$4(this, _repository).query(query);
994
1053
  }
995
1054
  async *[Symbol.asyncIterator]() {
996
1055
  for await (const [record] of this.getIterator(1)) {
@@ -1018,10 +1077,13 @@ const _Query = class {
1018
1077
  }
1019
1078
  return results;
1020
1079
  }
1021
- async getOne(options = {}) {
1080
+ async getFirst(options = {}) {
1022
1081
  const records = await this.getMany({ ...options, page: { size: 1 } });
1023
1082
  return records[0] || null;
1024
1083
  }
1084
+ cache(ttl) {
1085
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { cache: ttl }, __privateGet$4(this, _data));
1086
+ }
1025
1087
  nextPage(size, offset) {
1026
1088
  return this.firstPage(size, offset);
1027
1089
  }
@@ -1073,75 +1135,93 @@ function buildSortFilter(filter) {
1073
1135
  }
1074
1136
  }
1075
1137
 
1076
- var __accessCheck$3 = (obj, member, msg) => {
1138
+ var __accessCheck$4 = (obj, member, msg) => {
1077
1139
  if (!member.has(obj))
1078
1140
  throw TypeError("Cannot " + msg);
1079
1141
  };
1080
- var __privateGet$2 = (obj, member, getter) => {
1081
- __accessCheck$3(obj, member, "read from private field");
1142
+ var __privateGet$3 = (obj, member, getter) => {
1143
+ __accessCheck$4(obj, member, "read from private field");
1082
1144
  return getter ? getter.call(obj) : member.get(obj);
1083
1145
  };
1084
- var __privateAdd$3 = (obj, member, value) => {
1146
+ var __privateAdd$4 = (obj, member, value) => {
1085
1147
  if (member.has(obj))
1086
1148
  throw TypeError("Cannot add the same private member more than once");
1087
1149
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1088
1150
  };
1089
- var __privateSet$1 = (obj, member, value, setter) => {
1090
- __accessCheck$3(obj, member, "write to private field");
1151
+ var __privateSet$2 = (obj, member, value, setter) => {
1152
+ __accessCheck$4(obj, member, "write to private field");
1091
1153
  setter ? setter.call(obj, value) : member.set(obj, value);
1092
1154
  return value;
1093
1155
  };
1094
1156
  var __privateMethod$2 = (obj, member, method) => {
1095
- __accessCheck$3(obj, member, "access private method");
1157
+ __accessCheck$4(obj, member, "access private method");
1096
1158
  return method;
1097
1159
  };
1098
- var _table, _links, _getFetchProps, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn;
1160
+ 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
1161
  class Repository extends Query {
1100
1162
  }
1101
1163
  class RestRepository extends Query {
1102
1164
  constructor(options) {
1103
1165
  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);
1166
+ __privateAdd$4(this, _insertRecordWithoutId);
1167
+ __privateAdd$4(this, _insertRecordWithId);
1168
+ __privateAdd$4(this, _bulkInsertTableRecords);
1169
+ __privateAdd$4(this, _updateRecordWithID);
1170
+ __privateAdd$4(this, _upsertRecordWithID);
1171
+ __privateAdd$4(this, _deleteRecord);
1172
+ __privateAdd$4(this, _invalidateCache);
1173
+ __privateAdd$4(this, _setCacheRecord);
1174
+ __privateAdd$4(this, _getCacheRecord);
1175
+ __privateAdd$4(this, _setCacheQuery);
1176
+ __privateAdd$4(this, _getCacheQuery);
1177
+ __privateAdd$4(this, _table, void 0);
1178
+ __privateAdd$4(this, _links, void 0);
1179
+ __privateAdd$4(this, _getFetchProps, void 0);
1180
+ __privateAdd$4(this, _cache, void 0);
1181
+ __privateSet$2(this, _table, options.table);
1182
+ __privateSet$2(this, _links, options.links ?? {});
1183
+ __privateSet$2(this, _getFetchProps, options.pluginOptions.getFetchProps);
1116
1184
  this.db = options.db;
1185
+ __privateSet$2(this, _cache, options.pluginOptions.cache);
1117
1186
  }
1118
1187
  async create(a, b) {
1119
1188
  if (Array.isArray(a)) {
1120
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1189
+ const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1190
+ await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1191
+ return records;
1121
1192
  }
1122
1193
  if (isString(a) && isObject(b)) {
1123
1194
  if (a === "")
1124
1195
  throw new Error("The id can't be empty");
1125
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1196
+ const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1197
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1198
+ return record;
1126
1199
  }
1127
1200
  if (isObject(a) && isString(a.id)) {
1128
1201
  if (a.id === "")
1129
1202
  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 });
1203
+ const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1204
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1205
+ return record;
1131
1206
  }
1132
1207
  if (isObject(a)) {
1133
- return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1208
+ const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1209
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1210
+ return record;
1134
1211
  }
1135
1212
  throw new Error("Invalid arguments for create method");
1136
1213
  }
1137
1214
  async read(recordId) {
1138
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1215
+ const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, recordId);
1216
+ if (cacheRecord)
1217
+ return cacheRecord;
1218
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1139
1219
  try {
1140
1220
  const response = await getRecord({
1141
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1221
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1142
1222
  ...fetchProps
1143
1223
  });
1144
- return initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), response);
1224
+ return initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), response);
1145
1225
  } catch (e) {
1146
1226
  if (isObject(e) && e.status === 404) {
1147
1227
  return null;
@@ -1157,10 +1237,16 @@ class RestRepository extends Query {
1157
1237
  return Promise.all(a.map((object) => this.update(object)));
1158
1238
  }
1159
1239
  if (isString(a) && isObject(b)) {
1160
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1240
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1241
+ const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1242
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1243
+ return record;
1161
1244
  }
1162
1245
  if (isObject(a) && isString(a.id)) {
1163
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1246
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1247
+ const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1248
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1249
+ return record;
1164
1250
  }
1165
1251
  throw new Error("Invalid arguments for update method");
1166
1252
  }
@@ -1172,41 +1258,52 @@ class RestRepository extends Query {
1172
1258
  return Promise.all(a.map((object) => this.createOrUpdate(object)));
1173
1259
  }
1174
1260
  if (isString(a) && isObject(b)) {
1175
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1261
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1262
+ const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1263
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1264
+ return record;
1176
1265
  }
1177
1266
  if (isObject(a) && isString(a.id)) {
1178
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1267
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1268
+ const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1269
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1270
+ return record;
1179
1271
  }
1180
1272
  throw new Error("Invalid arguments for createOrUpdate method");
1181
1273
  }
1182
- async delete(recordId) {
1183
- if (Array.isArray(recordId)) {
1184
- if (recordId.length > 100) {
1274
+ async delete(a) {
1275
+ if (Array.isArray(a)) {
1276
+ if (a.length > 100) {
1185
1277
  console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1186
1278
  }
1187
- await Promise.all(recordId.map((id) => this.delete(id)));
1279
+ await Promise.all(a.map((id) => this.delete(id)));
1188
1280
  return;
1189
1281
  }
1190
- if (isString(recordId)) {
1191
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, recordId);
1282
+ if (isString(a)) {
1283
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1284
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1192
1285
  return;
1193
1286
  }
1194
- if (isObject(recordId) && isString(recordId.id)) {
1195
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, recordId.id);
1287
+ if (isObject(a) && isString(a.id)) {
1288
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1289
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1196
1290
  return;
1197
1291
  }
1198
1292
  throw new Error("Invalid arguments for delete method");
1199
1293
  }
1200
1294
  async search(query, options = {}) {
1201
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1295
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1202
1296
  const { records } = await searchBranch({
1203
1297
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1204
- body: { tables: [__privateGet$2(this, _table)], query, fuzziness: options.fuzziness },
1298
+ body: { tables: [__privateGet$3(this, _table)], query, fuzziness: options.fuzziness },
1205
1299
  ...fetchProps
1206
1300
  });
1207
- return records.map((item) => initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), item));
1301
+ return records.map((item) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), item));
1208
1302
  }
1209
1303
  async query(query) {
1304
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1305
+ if (cacheQuery)
1306
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
1210
1307
  const data = query.getQueryOptions();
1211
1308
  const body = {
1212
1309
  filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
@@ -1214,28 +1311,30 @@ class RestRepository extends Query {
1214
1311
  page: data.page,
1215
1312
  columns: data.columns
1216
1313
  };
1217
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1314
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1218
1315
  const { meta, records: objects } = await queryTable({
1219
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table) },
1316
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
1220
1317
  body,
1221
1318
  ...fetchProps
1222
1319
  });
1223
- const records = objects.map((record) => initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), record));
1320
+ const records = objects.map((record) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), record));
1321
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1224
1322
  return new Page(query, meta, records);
1225
1323
  }
1226
1324
  }
1227
1325
  _table = new WeakMap();
1228
1326
  _links = new WeakMap();
1229
1327
  _getFetchProps = new WeakMap();
1328
+ _cache = new WeakMap();
1230
1329
  _insertRecordWithoutId = new WeakSet();
1231
1330
  insertRecordWithoutId_fn = async function(object) {
1232
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1331
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1233
1332
  const record = transformObjectLinks(object);
1234
1333
  const response = await insertRecord({
1235
1334
  pathParams: {
1236
1335
  workspace: "{workspaceId}",
1237
1336
  dbBranchName: "{dbBranch}",
1238
- tableName: __privateGet$2(this, _table)
1337
+ tableName: __privateGet$3(this, _table)
1239
1338
  },
1240
1339
  body: record,
1241
1340
  ...fetchProps
@@ -1248,13 +1347,13 @@ insertRecordWithoutId_fn = async function(object) {
1248
1347
  };
1249
1348
  _insertRecordWithId = new WeakSet();
1250
1349
  insertRecordWithId_fn = async function(recordId, object) {
1251
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1350
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1252
1351
  const record = transformObjectLinks(object);
1253
1352
  const response = await insertRecordWithID({
1254
1353
  pathParams: {
1255
1354
  workspace: "{workspaceId}",
1256
1355
  dbBranchName: "{dbBranch}",
1257
- tableName: __privateGet$2(this, _table),
1356
+ tableName: __privateGet$3(this, _table),
1258
1357
  recordId
1259
1358
  },
1260
1359
  body: record,
@@ -1269,10 +1368,10 @@ insertRecordWithId_fn = async function(recordId, object) {
1269
1368
  };
1270
1369
  _bulkInsertTableRecords = new WeakSet();
1271
1370
  bulkInsertTableRecords_fn = async function(objects) {
1272
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1371
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1273
1372
  const records = objects.map((object) => transformObjectLinks(object));
1274
1373
  const response = await bulkInsertTableRecords({
1275
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table) },
1374
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
1276
1375
  body: { records },
1277
1376
  ...fetchProps
1278
1377
  });
@@ -1284,10 +1383,10 @@ bulkInsertTableRecords_fn = async function(objects) {
1284
1383
  };
1285
1384
  _updateRecordWithID = new WeakSet();
1286
1385
  updateRecordWithID_fn = async function(recordId, object) {
1287
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1386
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1288
1387
  const record = transformObjectLinks(object);
1289
1388
  const response = await updateRecordWithID({
1290
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1389
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1291
1390
  body: record,
1292
1391
  ...fetchProps
1293
1392
  });
@@ -1298,9 +1397,9 @@ updateRecordWithID_fn = async function(recordId, object) {
1298
1397
  };
1299
1398
  _upsertRecordWithID = new WeakSet();
1300
1399
  upsertRecordWithID_fn = async function(recordId, object) {
1301
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1400
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1302
1401
  const response = await upsertRecordWithID({
1303
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1402
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1304
1403
  body: object,
1305
1404
  ...fetchProps
1306
1405
  });
@@ -1311,12 +1410,51 @@ upsertRecordWithID_fn = async function(recordId, object) {
1311
1410
  };
1312
1411
  _deleteRecord = new WeakSet();
1313
1412
  deleteRecord_fn = async function(recordId) {
1314
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1413
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1315
1414
  await deleteRecord({
1316
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1415
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1317
1416
  ...fetchProps
1318
1417
  });
1319
1418
  };
1419
+ _invalidateCache = new WeakSet();
1420
+ invalidateCache_fn = async function(recordId) {
1421
+ await __privateGet$3(this, _cache).delete(`rec_${__privateGet$3(this, _table)}:${recordId}`);
1422
+ const cacheItems = await __privateGet$3(this, _cache).getAll();
1423
+ const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1424
+ for (const [key, value] of queries) {
1425
+ const ids = getIds(value);
1426
+ if (ids.includes(recordId))
1427
+ await __privateGet$3(this, _cache).delete(key);
1428
+ }
1429
+ };
1430
+ _setCacheRecord = new WeakSet();
1431
+ setCacheRecord_fn = async function(record) {
1432
+ if (!__privateGet$3(this, _cache).cacheRecords)
1433
+ return;
1434
+ await __privateGet$3(this, _cache).set(`rec_${__privateGet$3(this, _table)}:${record.id}`, record);
1435
+ };
1436
+ _getCacheRecord = new WeakSet();
1437
+ getCacheRecord_fn = async function(recordId) {
1438
+ if (!__privateGet$3(this, _cache).cacheRecords)
1439
+ return null;
1440
+ return __privateGet$3(this, _cache).get(`rec_${__privateGet$3(this, _table)}:${recordId}`);
1441
+ };
1442
+ _setCacheQuery = new WeakSet();
1443
+ setCacheQuery_fn = async function(query, meta, records) {
1444
+ await __privateGet$3(this, _cache).set(`query_${__privateGet$3(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
1445
+ };
1446
+ _getCacheQuery = new WeakSet();
1447
+ getCacheQuery_fn = async function(query) {
1448
+ const key = `query_${__privateGet$3(this, _table)}:${query.key()}`;
1449
+ const result = await __privateGet$3(this, _cache).get(key);
1450
+ if (!result)
1451
+ return null;
1452
+ const { cache: ttl = __privateGet$3(this, _cache).defaultQueryTTL } = query.getQueryOptions();
1453
+ if (!ttl || ttl < 0)
1454
+ return result;
1455
+ const hasExpired = result.date.getTime() + ttl < Date.now();
1456
+ return hasExpired ? null : result;
1457
+ };
1320
1458
  const transformObjectLinks = (object) => {
1321
1459
  return Object.entries(object).reduce((acc, [key, value]) => {
1322
1460
  if (key === "xata")
@@ -1350,6 +1488,65 @@ const initObject = (db, links, table, object) => {
1350
1488
  Object.freeze(result);
1351
1489
  return result;
1352
1490
  };
1491
+ function getIds(value) {
1492
+ if (Array.isArray(value)) {
1493
+ return value.map((item) => getIds(item)).flat();
1494
+ }
1495
+ if (!isObject(value))
1496
+ return [];
1497
+ const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1498
+ return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
1499
+ }
1500
+
1501
+ var __accessCheck$3 = (obj, member, msg) => {
1502
+ if (!member.has(obj))
1503
+ throw TypeError("Cannot " + msg);
1504
+ };
1505
+ var __privateGet$2 = (obj, member, getter) => {
1506
+ __accessCheck$3(obj, member, "read from private field");
1507
+ return getter ? getter.call(obj) : member.get(obj);
1508
+ };
1509
+ var __privateAdd$3 = (obj, member, value) => {
1510
+ if (member.has(obj))
1511
+ throw TypeError("Cannot add the same private member more than once");
1512
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1513
+ };
1514
+ var __privateSet$1 = (obj, member, value, setter) => {
1515
+ __accessCheck$3(obj, member, "write to private field");
1516
+ setter ? setter.call(obj, value) : member.set(obj, value);
1517
+ return value;
1518
+ };
1519
+ var _map;
1520
+ class SimpleCache {
1521
+ constructor(options = {}) {
1522
+ __privateAdd$3(this, _map, void 0);
1523
+ __privateSet$1(this, _map, /* @__PURE__ */ new Map());
1524
+ this.capacity = options.max ?? 500;
1525
+ this.cacheRecords = options.cacheRecords ?? true;
1526
+ this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1527
+ }
1528
+ async getAll() {
1529
+ return Object.fromEntries(__privateGet$2(this, _map));
1530
+ }
1531
+ async get(key) {
1532
+ return __privateGet$2(this, _map).get(key) ?? null;
1533
+ }
1534
+ async set(key, value) {
1535
+ await this.delete(key);
1536
+ __privateGet$2(this, _map).set(key, value);
1537
+ if (__privateGet$2(this, _map).size > this.capacity) {
1538
+ const leastRecentlyUsed = __privateGet$2(this, _map).keys().next().value;
1539
+ await this.delete(leastRecentlyUsed);
1540
+ }
1541
+ }
1542
+ async delete(key) {
1543
+ __privateGet$2(this, _map).delete(key);
1544
+ }
1545
+ async clear() {
1546
+ return __privateGet$2(this, _map).clear();
1547
+ }
1548
+ }
1549
+ _map = new WeakMap();
1353
1550
 
1354
1551
  const gt = (value) => ({ $gt: value });
1355
1552
  const ge = (value) => ({ $ge: value });
@@ -1391,20 +1588,20 @@ class SchemaPlugin extends XataPlugin {
1391
1588
  this.tableNames = tableNames;
1392
1589
  __privateAdd$2(this, _tables, {});
1393
1590
  }
1394
- build(options) {
1395
- const { getFetchProps } = options;
1591
+ build(pluginOptions) {
1396
1592
  const links = this.links;
1397
1593
  const db = new Proxy({}, {
1398
1594
  get: (_target, table) => {
1399
1595
  if (!isString(table))
1400
1596
  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 });
1597
+ if (!__privateGet$1(this, _tables)[table]) {
1598
+ __privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, links });
1599
+ }
1403
1600
  return __privateGet$1(this, _tables)[table];
1404
1601
  }
1405
1602
  });
1406
1603
  for (const table of this.tableNames ?? []) {
1407
- db[table] = new RestRepository({ db, getFetchProps, table, links });
1604
+ db[table] = new RestRepository({ db, pluginOptions, table, links });
1408
1605
  }
1409
1606
  return db;
1410
1607
  }
@@ -1578,16 +1775,18 @@ const buildClient = (plugins) => {
1578
1775
  __privateAdd(this, _evaluateBranch);
1579
1776
  __privateAdd(this, _branch, void 0);
1580
1777
  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
- });
1778
+ const pluginOptions = {
1779
+ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
1780
+ cache: safeOptions.cache
1781
+ };
1782
+ const db = new SchemaPlugin(links, tables).build(pluginOptions);
1783
+ const search = new SearchPlugin(db, links ?? {}).build(pluginOptions);
1585
1784
  this.db = db;
1586
1785
  this.search = search;
1587
1786
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
1588
1787
  if (!namespace)
1589
1788
  continue;
1590
- const result = namespace.build({ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions) });
1789
+ const result = namespace.build(pluginOptions);
1591
1790
  if (result instanceof Promise) {
1592
1791
  void result.then((namespace2) => {
1593
1792
  this[key] = namespace2;
@@ -1601,11 +1800,12 @@ const buildClient = (plugins) => {
1601
1800
  const fetch = getFetchImplementation(options?.fetch);
1602
1801
  const databaseURL = options?.databaseURL || getDatabaseURL();
1603
1802
  const apiKey = options?.apiKey || getAPIKey();
1803
+ const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
1604
1804
  const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
1605
1805
  if (!databaseURL || !apiKey) {
1606
1806
  throw new Error("Options databaseURL and apiKey are required");
1607
1807
  }
1608
- return { fetch, databaseURL, apiKey, branch };
1808
+ return { fetch, databaseURL, apiKey, branch, cache };
1609
1809
  }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
1610
1810
  fetch,
1611
1811
  apiKey,
@@ -1665,11 +1865,13 @@ exports.Repository = Repository;
1665
1865
  exports.RestRepository = RestRepository;
1666
1866
  exports.SchemaPlugin = SchemaPlugin;
1667
1867
  exports.SearchPlugin = SearchPlugin;
1868
+ exports.SimpleCache = SimpleCache;
1668
1869
  exports.XataApiClient = XataApiClient;
1669
1870
  exports.XataApiPlugin = XataApiPlugin;
1670
1871
  exports.XataError = XataError;
1671
1872
  exports.XataPlugin = XataPlugin;
1672
1873
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
1874
+ exports.addGitBranchesEntry = addGitBranchesEntry;
1673
1875
  exports.addTableColumn = addTableColumn;
1674
1876
  exports.buildClient = buildClient;
1675
1877
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
@@ -1704,6 +1906,7 @@ exports.getCurrentBranchDetails = getCurrentBranchDetails;
1704
1906
  exports.getCurrentBranchName = getCurrentBranchName;
1705
1907
  exports.getDatabaseList = getDatabaseList;
1706
1908
  exports.getDatabaseURL = getDatabaseURL;
1909
+ exports.getGitBranchesMapping = getGitBranchesMapping;
1707
1910
  exports.getRecord = getRecord;
1708
1911
  exports.getTableColumns = getTableColumns;
1709
1912
  exports.getTableSchema = getTableSchema;
@@ -1732,8 +1935,10 @@ exports.notExists = notExists;
1732
1935
  exports.operationsByTag = operationsByTag;
1733
1936
  exports.pattern = pattern;
1734
1937
  exports.queryTable = queryTable;
1938
+ exports.removeGitBranchesEntry = removeGitBranchesEntry;
1735
1939
  exports.removeWorkspaceMember = removeWorkspaceMember;
1736
1940
  exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
1941
+ exports.resolveBranch = resolveBranch;
1737
1942
  exports.searchBranch = searchBranch;
1738
1943
  exports.setTableSchema = setTableSchema;
1739
1944
  exports.startsWith = startsWith;