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