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

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,58 +1006,64 @@ 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
- for await (const [record] of this.getIterator(1)) {
1055
+ for await (const [record] of this.getIterator({ batchSize: 1 })) {
997
1056
  yield record;
998
1057
  }
999
1058
  }
1000
- async *getIterator(chunk, options = {}) {
1059
+ async *getIterator(options = {}) {
1060
+ const { batchSize = 1 } = options;
1001
1061
  let offset = 0;
1002
1062
  let end = false;
1003
1063
  while (!end) {
1004
- const { records, meta } = await this.getPaginated({ ...options, page: { size: chunk, offset } });
1064
+ const { records, meta } = await this.getPaginated({ ...options, page: { size: batchSize, offset } });
1005
1065
  yield records;
1006
- offset += chunk;
1066
+ offset += batchSize;
1007
1067
  end = !meta.page.more;
1008
1068
  }
1009
1069
  }
@@ -1011,17 +1071,21 @@ const _Query = class {
1011
1071
  const { records } = await this.getPaginated(options);
1012
1072
  return records;
1013
1073
  }
1014
- async getAll(chunk = PAGINATION_MAX_SIZE, options = {}) {
1074
+ async getAll(options = {}) {
1075
+ const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
1015
1076
  const results = [];
1016
- for await (const page of this.getIterator(chunk, options)) {
1077
+ for await (const page of this.getIterator({ ...rest, batchSize })) {
1017
1078
  results.push(...page);
1018
1079
  }
1019
1080
  return results;
1020
1081
  }
1021
- async getOne(options = {}) {
1082
+ async getFirst(options = {}) {
1022
1083
  const records = await this.getMany({ ...options, page: { size: 1 } });
1023
1084
  return records[0] || null;
1024
1085
  }
1086
+ cache(ttl) {
1087
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { cache: ttl }, __privateGet$4(this, _data));
1088
+ }
1025
1089
  nextPage(size, offset) {
1026
1090
  return this.firstPage(size, offset);
1027
1091
  }
@@ -1073,75 +1137,93 @@ function buildSortFilter(filter) {
1073
1137
  }
1074
1138
  }
1075
1139
 
1076
- var __accessCheck$3 = (obj, member, msg) => {
1140
+ var __accessCheck$4 = (obj, member, msg) => {
1077
1141
  if (!member.has(obj))
1078
1142
  throw TypeError("Cannot " + msg);
1079
1143
  };
1080
- var __privateGet$2 = (obj, member, getter) => {
1081
- __accessCheck$3(obj, member, "read from private field");
1144
+ var __privateGet$3 = (obj, member, getter) => {
1145
+ __accessCheck$4(obj, member, "read from private field");
1082
1146
  return getter ? getter.call(obj) : member.get(obj);
1083
1147
  };
1084
- var __privateAdd$3 = (obj, member, value) => {
1148
+ var __privateAdd$4 = (obj, member, value) => {
1085
1149
  if (member.has(obj))
1086
1150
  throw TypeError("Cannot add the same private member more than once");
1087
1151
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1088
1152
  };
1089
- var __privateSet$1 = (obj, member, value, setter) => {
1090
- __accessCheck$3(obj, member, "write to private field");
1153
+ var __privateSet$2 = (obj, member, value, setter) => {
1154
+ __accessCheck$4(obj, member, "write to private field");
1091
1155
  setter ? setter.call(obj, value) : member.set(obj, value);
1092
1156
  return value;
1093
1157
  };
1094
1158
  var __privateMethod$2 = (obj, member, method) => {
1095
- __accessCheck$3(obj, member, "access private method");
1159
+ __accessCheck$4(obj, member, "access private method");
1096
1160
  return method;
1097
1161
  };
1098
- var _table, _links, _getFetchProps, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn;
1162
+ 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
1163
  class Repository extends Query {
1100
1164
  }
1101
1165
  class RestRepository extends Query {
1102
1166
  constructor(options) {
1103
1167
  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);
1168
+ __privateAdd$4(this, _insertRecordWithoutId);
1169
+ __privateAdd$4(this, _insertRecordWithId);
1170
+ __privateAdd$4(this, _bulkInsertTableRecords);
1171
+ __privateAdd$4(this, _updateRecordWithID);
1172
+ __privateAdd$4(this, _upsertRecordWithID);
1173
+ __privateAdd$4(this, _deleteRecord);
1174
+ __privateAdd$4(this, _invalidateCache);
1175
+ __privateAdd$4(this, _setCacheRecord);
1176
+ __privateAdd$4(this, _getCacheRecord);
1177
+ __privateAdd$4(this, _setCacheQuery);
1178
+ __privateAdd$4(this, _getCacheQuery);
1179
+ __privateAdd$4(this, _table, void 0);
1180
+ __privateAdd$4(this, _links, void 0);
1181
+ __privateAdd$4(this, _getFetchProps, void 0);
1182
+ __privateAdd$4(this, _cache, void 0);
1183
+ __privateSet$2(this, _table, options.table);
1184
+ __privateSet$2(this, _links, options.links ?? {});
1185
+ __privateSet$2(this, _getFetchProps, options.pluginOptions.getFetchProps);
1116
1186
  this.db = options.db;
1187
+ __privateSet$2(this, _cache, options.pluginOptions.cache);
1117
1188
  }
1118
1189
  async create(a, b) {
1119
1190
  if (Array.isArray(a)) {
1120
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1191
+ const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1192
+ await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1193
+ return records;
1121
1194
  }
1122
1195
  if (isString(a) && isObject(b)) {
1123
1196
  if (a === "")
1124
1197
  throw new Error("The id can't be empty");
1125
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1198
+ const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1199
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1200
+ return record;
1126
1201
  }
1127
1202
  if (isObject(a) && isString(a.id)) {
1128
1203
  if (a.id === "")
1129
1204
  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 });
1205
+ const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1206
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1207
+ return record;
1131
1208
  }
1132
1209
  if (isObject(a)) {
1133
- return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1210
+ const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1211
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1212
+ return record;
1134
1213
  }
1135
1214
  throw new Error("Invalid arguments for create method");
1136
1215
  }
1137
1216
  async read(recordId) {
1138
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1217
+ const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, recordId);
1218
+ if (cacheRecord)
1219
+ return cacheRecord;
1220
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1139
1221
  try {
1140
1222
  const response = await getRecord({
1141
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1223
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1142
1224
  ...fetchProps
1143
1225
  });
1144
- return initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), response);
1226
+ return initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), response);
1145
1227
  } catch (e) {
1146
1228
  if (isObject(e) && e.status === 404) {
1147
1229
  return null;
@@ -1157,10 +1239,16 @@ class RestRepository extends Query {
1157
1239
  return Promise.all(a.map((object) => this.update(object)));
1158
1240
  }
1159
1241
  if (isString(a) && isObject(b)) {
1160
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1242
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1243
+ const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1244
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1245
+ return record;
1161
1246
  }
1162
1247
  if (isObject(a) && isString(a.id)) {
1163
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1248
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1249
+ const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1250
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1251
+ return record;
1164
1252
  }
1165
1253
  throw new Error("Invalid arguments for update method");
1166
1254
  }
@@ -1172,41 +1260,52 @@ class RestRepository extends Query {
1172
1260
  return Promise.all(a.map((object) => this.createOrUpdate(object)));
1173
1261
  }
1174
1262
  if (isString(a) && isObject(b)) {
1175
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1263
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1264
+ const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1265
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1266
+ return record;
1176
1267
  }
1177
1268
  if (isObject(a) && isString(a.id)) {
1178
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1269
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1270
+ const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1271
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1272
+ return record;
1179
1273
  }
1180
1274
  throw new Error("Invalid arguments for createOrUpdate method");
1181
1275
  }
1182
- async delete(recordId) {
1183
- if (Array.isArray(recordId)) {
1184
- if (recordId.length > 100) {
1276
+ async delete(a) {
1277
+ if (Array.isArray(a)) {
1278
+ if (a.length > 100) {
1185
1279
  console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1186
1280
  }
1187
- await Promise.all(recordId.map((id) => this.delete(id)));
1281
+ await Promise.all(a.map((id) => this.delete(id)));
1188
1282
  return;
1189
1283
  }
1190
- if (isString(recordId)) {
1191
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, recordId);
1284
+ if (isString(a)) {
1285
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1286
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1192
1287
  return;
1193
1288
  }
1194
- if (isObject(recordId) && isString(recordId.id)) {
1195
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, recordId.id);
1289
+ if (isObject(a) && isString(a.id)) {
1290
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1291
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1196
1292
  return;
1197
1293
  }
1198
1294
  throw new Error("Invalid arguments for delete method");
1199
1295
  }
1200
1296
  async search(query, options = {}) {
1201
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1297
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1202
1298
  const { records } = await searchBranch({
1203
1299
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1204
- body: { tables: [__privateGet$2(this, _table)], query, fuzziness: options.fuzziness },
1300
+ body: { tables: [__privateGet$3(this, _table)], query, fuzziness: options.fuzziness },
1205
1301
  ...fetchProps
1206
1302
  });
1207
- return records.map((item) => initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), item));
1303
+ return records.map((item) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), item));
1208
1304
  }
1209
1305
  async query(query) {
1306
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1307
+ if (cacheQuery)
1308
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
1210
1309
  const data = query.getQueryOptions();
1211
1310
  const body = {
1212
1311
  filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
@@ -1214,28 +1313,30 @@ class RestRepository extends Query {
1214
1313
  page: data.page,
1215
1314
  columns: data.columns
1216
1315
  };
1217
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1316
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1218
1317
  const { meta, records: objects } = await queryTable({
1219
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table) },
1318
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
1220
1319
  body,
1221
1320
  ...fetchProps
1222
1321
  });
1223
- const records = objects.map((record) => initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), record));
1322
+ const records = objects.map((record) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), record));
1323
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1224
1324
  return new Page(query, meta, records);
1225
1325
  }
1226
1326
  }
1227
1327
  _table = new WeakMap();
1228
1328
  _links = new WeakMap();
1229
1329
  _getFetchProps = new WeakMap();
1330
+ _cache = new WeakMap();
1230
1331
  _insertRecordWithoutId = new WeakSet();
1231
1332
  insertRecordWithoutId_fn = async function(object) {
1232
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1333
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1233
1334
  const record = transformObjectLinks(object);
1234
1335
  const response = await insertRecord({
1235
1336
  pathParams: {
1236
1337
  workspace: "{workspaceId}",
1237
1338
  dbBranchName: "{dbBranch}",
1238
- tableName: __privateGet$2(this, _table)
1339
+ tableName: __privateGet$3(this, _table)
1239
1340
  },
1240
1341
  body: record,
1241
1342
  ...fetchProps
@@ -1248,13 +1349,13 @@ insertRecordWithoutId_fn = async function(object) {
1248
1349
  };
1249
1350
  _insertRecordWithId = new WeakSet();
1250
1351
  insertRecordWithId_fn = async function(recordId, object) {
1251
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1352
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1252
1353
  const record = transformObjectLinks(object);
1253
1354
  const response = await insertRecordWithID({
1254
1355
  pathParams: {
1255
1356
  workspace: "{workspaceId}",
1256
1357
  dbBranchName: "{dbBranch}",
1257
- tableName: __privateGet$2(this, _table),
1358
+ tableName: __privateGet$3(this, _table),
1258
1359
  recordId
1259
1360
  },
1260
1361
  body: record,
@@ -1269,10 +1370,10 @@ insertRecordWithId_fn = async function(recordId, object) {
1269
1370
  };
1270
1371
  _bulkInsertTableRecords = new WeakSet();
1271
1372
  bulkInsertTableRecords_fn = async function(objects) {
1272
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1373
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1273
1374
  const records = objects.map((object) => transformObjectLinks(object));
1274
1375
  const response = await bulkInsertTableRecords({
1275
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table) },
1376
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
1276
1377
  body: { records },
1277
1378
  ...fetchProps
1278
1379
  });
@@ -1284,10 +1385,10 @@ bulkInsertTableRecords_fn = async function(objects) {
1284
1385
  };
1285
1386
  _updateRecordWithID = new WeakSet();
1286
1387
  updateRecordWithID_fn = async function(recordId, object) {
1287
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1388
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1288
1389
  const record = transformObjectLinks(object);
1289
1390
  const response = await updateRecordWithID({
1290
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1391
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1291
1392
  body: record,
1292
1393
  ...fetchProps
1293
1394
  });
@@ -1298,9 +1399,9 @@ updateRecordWithID_fn = async function(recordId, object) {
1298
1399
  };
1299
1400
  _upsertRecordWithID = new WeakSet();
1300
1401
  upsertRecordWithID_fn = async function(recordId, object) {
1301
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1402
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1302
1403
  const response = await upsertRecordWithID({
1303
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1404
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1304
1405
  body: object,
1305
1406
  ...fetchProps
1306
1407
  });
@@ -1311,12 +1412,51 @@ upsertRecordWithID_fn = async function(recordId, object) {
1311
1412
  };
1312
1413
  _deleteRecord = new WeakSet();
1313
1414
  deleteRecord_fn = async function(recordId) {
1314
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1415
+ const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1315
1416
  await deleteRecord({
1316
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1417
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1317
1418
  ...fetchProps
1318
1419
  });
1319
1420
  };
1421
+ _invalidateCache = new WeakSet();
1422
+ invalidateCache_fn = async function(recordId) {
1423
+ await __privateGet$3(this, _cache).delete(`rec_${__privateGet$3(this, _table)}:${recordId}`);
1424
+ const cacheItems = await __privateGet$3(this, _cache).getAll();
1425
+ const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1426
+ for (const [key, value] of queries) {
1427
+ const ids = getIds(value);
1428
+ if (ids.includes(recordId))
1429
+ await __privateGet$3(this, _cache).delete(key);
1430
+ }
1431
+ };
1432
+ _setCacheRecord = new WeakSet();
1433
+ setCacheRecord_fn = async function(record) {
1434
+ if (!__privateGet$3(this, _cache).cacheRecords)
1435
+ return;
1436
+ await __privateGet$3(this, _cache).set(`rec_${__privateGet$3(this, _table)}:${record.id}`, record);
1437
+ };
1438
+ _getCacheRecord = new WeakSet();
1439
+ getCacheRecord_fn = async function(recordId) {
1440
+ if (!__privateGet$3(this, _cache).cacheRecords)
1441
+ return null;
1442
+ return __privateGet$3(this, _cache).get(`rec_${__privateGet$3(this, _table)}:${recordId}`);
1443
+ };
1444
+ _setCacheQuery = new WeakSet();
1445
+ setCacheQuery_fn = async function(query, meta, records) {
1446
+ await __privateGet$3(this, _cache).set(`query_${__privateGet$3(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
1447
+ };
1448
+ _getCacheQuery = new WeakSet();
1449
+ getCacheQuery_fn = async function(query) {
1450
+ const key = `query_${__privateGet$3(this, _table)}:${query.key()}`;
1451
+ const result = await __privateGet$3(this, _cache).get(key);
1452
+ if (!result)
1453
+ return null;
1454
+ const { cache: ttl = __privateGet$3(this, _cache).defaultQueryTTL } = query.getQueryOptions();
1455
+ if (!ttl || ttl < 0)
1456
+ return result;
1457
+ const hasExpired = result.date.getTime() + ttl < Date.now();
1458
+ return hasExpired ? null : result;
1459
+ };
1320
1460
  const transformObjectLinks = (object) => {
1321
1461
  return Object.entries(object).reduce((acc, [key, value]) => {
1322
1462
  if (key === "xata")
@@ -1350,6 +1490,65 @@ const initObject = (db, links, table, object) => {
1350
1490
  Object.freeze(result);
1351
1491
  return result;
1352
1492
  };
1493
+ function getIds(value) {
1494
+ if (Array.isArray(value)) {
1495
+ return value.map((item) => getIds(item)).flat();
1496
+ }
1497
+ if (!isObject(value))
1498
+ return [];
1499
+ const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1500
+ return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
1501
+ }
1502
+
1503
+ var __accessCheck$3 = (obj, member, msg) => {
1504
+ if (!member.has(obj))
1505
+ throw TypeError("Cannot " + msg);
1506
+ };
1507
+ var __privateGet$2 = (obj, member, getter) => {
1508
+ __accessCheck$3(obj, member, "read from private field");
1509
+ return getter ? getter.call(obj) : member.get(obj);
1510
+ };
1511
+ var __privateAdd$3 = (obj, member, value) => {
1512
+ if (member.has(obj))
1513
+ throw TypeError("Cannot add the same private member more than once");
1514
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1515
+ };
1516
+ var __privateSet$1 = (obj, member, value, setter) => {
1517
+ __accessCheck$3(obj, member, "write to private field");
1518
+ setter ? setter.call(obj, value) : member.set(obj, value);
1519
+ return value;
1520
+ };
1521
+ var _map;
1522
+ class SimpleCache {
1523
+ constructor(options = {}) {
1524
+ __privateAdd$3(this, _map, void 0);
1525
+ __privateSet$1(this, _map, /* @__PURE__ */ new Map());
1526
+ this.capacity = options.max ?? 500;
1527
+ this.cacheRecords = options.cacheRecords ?? true;
1528
+ this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1529
+ }
1530
+ async getAll() {
1531
+ return Object.fromEntries(__privateGet$2(this, _map));
1532
+ }
1533
+ async get(key) {
1534
+ return __privateGet$2(this, _map).get(key) ?? null;
1535
+ }
1536
+ async set(key, value) {
1537
+ await this.delete(key);
1538
+ __privateGet$2(this, _map).set(key, value);
1539
+ if (__privateGet$2(this, _map).size > this.capacity) {
1540
+ const leastRecentlyUsed = __privateGet$2(this, _map).keys().next().value;
1541
+ await this.delete(leastRecentlyUsed);
1542
+ }
1543
+ }
1544
+ async delete(key) {
1545
+ __privateGet$2(this, _map).delete(key);
1546
+ }
1547
+ async clear() {
1548
+ return __privateGet$2(this, _map).clear();
1549
+ }
1550
+ }
1551
+ _map = new WeakMap();
1353
1552
 
1354
1553
  const gt = (value) => ({ $gt: value });
1355
1554
  const ge = (value) => ({ $ge: value });
@@ -1391,20 +1590,20 @@ class SchemaPlugin extends XataPlugin {
1391
1590
  this.tableNames = tableNames;
1392
1591
  __privateAdd$2(this, _tables, {});
1393
1592
  }
1394
- build(options) {
1395
- const { getFetchProps } = options;
1593
+ build(pluginOptions) {
1396
1594
  const links = this.links;
1397
1595
  const db = new Proxy({}, {
1398
1596
  get: (_target, table) => {
1399
1597
  if (!isString(table))
1400
1598
  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 });
1599
+ if (!__privateGet$1(this, _tables)[table]) {
1600
+ __privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, links });
1601
+ }
1403
1602
  return __privateGet$1(this, _tables)[table];
1404
1603
  }
1405
1604
  });
1406
1605
  for (const table of this.tableNames ?? []) {
1407
- db[table] = new RestRepository({ db, getFetchProps, table, links });
1606
+ db[table] = new RestRepository({ db, pluginOptions, table, links });
1408
1607
  }
1409
1608
  return db;
1410
1609
  }
@@ -1578,16 +1777,18 @@ const buildClient = (plugins) => {
1578
1777
  __privateAdd(this, _evaluateBranch);
1579
1778
  __privateAdd(this, _branch, void 0);
1580
1779
  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
- });
1780
+ const pluginOptions = {
1781
+ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
1782
+ cache: safeOptions.cache
1783
+ };
1784
+ const db = new SchemaPlugin(links, tables).build(pluginOptions);
1785
+ const search = new SearchPlugin(db, links ?? {}).build(pluginOptions);
1585
1786
  this.db = db;
1586
1787
  this.search = search;
1587
1788
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
1588
1789
  if (!namespace)
1589
1790
  continue;
1590
- const result = namespace.build({ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions) });
1791
+ const result = namespace.build(pluginOptions);
1591
1792
  if (result instanceof Promise) {
1592
1793
  void result.then((namespace2) => {
1593
1794
  this[key] = namespace2;
@@ -1601,11 +1802,12 @@ const buildClient = (plugins) => {
1601
1802
  const fetch = getFetchImplementation(options?.fetch);
1602
1803
  const databaseURL = options?.databaseURL || getDatabaseURL();
1603
1804
  const apiKey = options?.apiKey || getAPIKey();
1805
+ const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
1604
1806
  const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
1605
1807
  if (!databaseURL || !apiKey) {
1606
1808
  throw new Error("Options databaseURL and apiKey are required");
1607
1809
  }
1608
- return { fetch, databaseURL, apiKey, branch };
1810
+ return { fetch, databaseURL, apiKey, branch, cache };
1609
1811
  }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
1610
1812
  fetch,
1611
1813
  apiKey,
@@ -1665,11 +1867,13 @@ exports.Repository = Repository;
1665
1867
  exports.RestRepository = RestRepository;
1666
1868
  exports.SchemaPlugin = SchemaPlugin;
1667
1869
  exports.SearchPlugin = SearchPlugin;
1870
+ exports.SimpleCache = SimpleCache;
1668
1871
  exports.XataApiClient = XataApiClient;
1669
1872
  exports.XataApiPlugin = XataApiPlugin;
1670
1873
  exports.XataError = XataError;
1671
1874
  exports.XataPlugin = XataPlugin;
1672
1875
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
1876
+ exports.addGitBranchesEntry = addGitBranchesEntry;
1673
1877
  exports.addTableColumn = addTableColumn;
1674
1878
  exports.buildClient = buildClient;
1675
1879
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
@@ -1704,6 +1908,7 @@ exports.getCurrentBranchDetails = getCurrentBranchDetails;
1704
1908
  exports.getCurrentBranchName = getCurrentBranchName;
1705
1909
  exports.getDatabaseList = getDatabaseList;
1706
1910
  exports.getDatabaseURL = getDatabaseURL;
1911
+ exports.getGitBranchesMapping = getGitBranchesMapping;
1707
1912
  exports.getRecord = getRecord;
1708
1913
  exports.getTableColumns = getTableColumns;
1709
1914
  exports.getTableSchema = getTableSchema;
@@ -1732,8 +1937,10 @@ exports.notExists = notExists;
1732
1937
  exports.operationsByTag = operationsByTag;
1733
1938
  exports.pattern = pattern;
1734
1939
  exports.queryTable = queryTable;
1940
+ exports.removeGitBranchesEntry = removeGitBranchesEntry;
1735
1941
  exports.removeWorkspaceMember = removeWorkspaceMember;
1736
1942
  exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
1943
+ exports.resolveBranch = resolveBranch;
1737
1944
  exports.searchBranch = searchBranch;
1738
1945
  exports.setTableSchema = setTableSchema;
1739
1946
  exports.startsWith = startsWith;