@xata.io/client 0.0.0-alpha.vf231460 → 0.0.0-alpha.vf3081bb

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
@@ -7,8 +7,18 @@ function compact(arr) {
7
7
  function isObject(value) {
8
8
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
9
9
  }
10
+ function isDefined(value) {
11
+ return value !== null && value !== void 0;
12
+ }
10
13
  function isString(value) {
11
- return value !== void 0 && value !== null && typeof value === "string";
14
+ return isDefined(value) && typeof value === "string";
15
+ }
16
+ function toBase64(value) {
17
+ try {
18
+ return btoa(value);
19
+ } catch (err) {
20
+ return Buffer.from(value).toString("base64");
21
+ }
12
22
  }
13
23
 
14
24
  function getEnvVariable(name) {
@@ -27,7 +37,10 @@ function getEnvVariable(name) {
27
37
  }
28
38
  async function getGitBranch() {
29
39
  try {
30
- return require("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
40
+ if (typeof require === "function") {
41
+ const req = require;
42
+ return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
43
+ }
31
44
  } catch (err) {
32
45
  }
33
46
  try {
@@ -60,7 +73,12 @@ function getFetchImplementation(userFetch) {
60
73
  return fetchImpl;
61
74
  }
62
75
 
63
- class FetcherError extends Error {
76
+ class ErrorWithCause extends Error {
77
+ constructor(message, options) {
78
+ super(message, options);
79
+ }
80
+ }
81
+ class FetcherError extends ErrorWithCause {
64
82
  constructor(status, data) {
65
83
  super(getMessage(data));
66
84
  this.status = status;
@@ -241,6 +259,14 @@ const deleteDatabase = (variables) => fetch$1({
241
259
  method: "delete",
242
260
  ...variables
243
261
  });
262
+ const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
263
+ const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
264
+ const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
265
+ const resolveBranch = (variables) => fetch$1({
266
+ url: "/dbs/{dbName}/resolveBranch",
267
+ method: "get",
268
+ ...variables
269
+ });
244
270
  const getBranchDetails = (variables) => fetch$1({
245
271
  url: "/db/{dbBranchName}",
246
272
  method: "get",
@@ -348,6 +374,11 @@ const queryTable = (variables) => fetch$1({
348
374
  method: "post",
349
375
  ...variables
350
376
  });
377
+ const searchTable = (variables) => fetch$1({
378
+ url: "/db/{dbBranchName}/tables/{tableName}/search",
379
+ method: "post",
380
+ ...variables
381
+ });
351
382
  const searchBranch = (variables) => fetch$1({
352
383
  url: "/db/{dbBranchName}/search",
353
384
  method: "post",
@@ -369,7 +400,15 @@ const operationsByTag = {
369
400
  resendWorkspaceMemberInvite,
370
401
  acceptWorkspaceMemberInvite
371
402
  },
372
- database: { getDatabaseList, createDatabase, deleteDatabase },
403
+ database: {
404
+ getDatabaseList,
405
+ createDatabase,
406
+ deleteDatabase,
407
+ getGitBranchesMapping,
408
+ addGitBranchesEntry,
409
+ removeGitBranchesEntry,
410
+ resolveBranch
411
+ },
373
412
  branch: {
374
413
  getBranchList,
375
414
  getBranchDetails,
@@ -403,6 +442,7 @@ const operationsByTag = {
403
442
  getRecord,
404
443
  bulkInsertTableRecords,
405
444
  queryTable,
445
+ searchTable,
406
446
  searchBranch
407
447
  }
408
448
  };
@@ -432,35 +472,35 @@ function isValidBuilder(builder) {
432
472
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
433
473
  }
434
474
 
435
- var __accessCheck$6 = (obj, member, msg) => {
475
+ var __accessCheck$7 = (obj, member, msg) => {
436
476
  if (!member.has(obj))
437
477
  throw TypeError("Cannot " + msg);
438
478
  };
439
- var __privateGet$5 = (obj, member, getter) => {
440
- __accessCheck$6(obj, member, "read from private field");
479
+ var __privateGet$7 = (obj, member, getter) => {
480
+ __accessCheck$7(obj, member, "read from private field");
441
481
  return getter ? getter.call(obj) : member.get(obj);
442
482
  };
443
- var __privateAdd$6 = (obj, member, value) => {
483
+ var __privateAdd$7 = (obj, member, value) => {
444
484
  if (member.has(obj))
445
485
  throw TypeError("Cannot add the same private member more than once");
446
486
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
447
487
  };
448
- var __privateSet$4 = (obj, member, value, setter) => {
449
- __accessCheck$6(obj, member, "write to private field");
488
+ var __privateSet$6 = (obj, member, value, setter) => {
489
+ __accessCheck$7(obj, member, "write to private field");
450
490
  setter ? setter.call(obj, value) : member.set(obj, value);
451
491
  return value;
452
492
  };
453
493
  var _extraProps, _namespaces;
454
494
  class XataApiClient {
455
495
  constructor(options = {}) {
456
- __privateAdd$6(this, _extraProps, void 0);
457
- __privateAdd$6(this, _namespaces, {});
496
+ __privateAdd$7(this, _extraProps, void 0);
497
+ __privateAdd$7(this, _namespaces, {});
458
498
  const provider = options.host ?? "production";
459
499
  const apiKey = options?.apiKey ?? getAPIKey();
460
500
  if (!apiKey) {
461
501
  throw new Error("Could not resolve a valid apiKey");
462
502
  }
463
- __privateSet$4(this, _extraProps, {
503
+ __privateSet$6(this, _extraProps, {
464
504
  apiUrl: getHostUrl(provider, "main"),
465
505
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
466
506
  fetchImpl: getFetchImplementation(options.fetch),
@@ -468,34 +508,34 @@ class XataApiClient {
468
508
  });
469
509
  }
470
510
  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;
511
+ if (!__privateGet$7(this, _namespaces).user)
512
+ __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
513
+ return __privateGet$7(this, _namespaces).user;
474
514
  }
475
515
  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;
516
+ if (!__privateGet$7(this, _namespaces).workspaces)
517
+ __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
518
+ return __privateGet$7(this, _namespaces).workspaces;
479
519
  }
480
520
  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;
521
+ if (!__privateGet$7(this, _namespaces).databases)
522
+ __privateGet$7(this, _namespaces).databases = new DatabaseApi(__privateGet$7(this, _extraProps));
523
+ return __privateGet$7(this, _namespaces).databases;
484
524
  }
485
525
  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;
526
+ if (!__privateGet$7(this, _namespaces).branches)
527
+ __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
528
+ return __privateGet$7(this, _namespaces).branches;
489
529
  }
490
530
  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;
531
+ if (!__privateGet$7(this, _namespaces).tables)
532
+ __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
533
+ return __privateGet$7(this, _namespaces).tables;
494
534
  }
495
535
  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;
536
+ if (!__privateGet$7(this, _namespaces).records)
537
+ __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
538
+ return __privateGet$7(this, _namespaces).records;
499
539
  }
500
540
  }
501
541
  _extraProps = new WeakMap();
@@ -629,6 +669,33 @@ class DatabaseApi {
629
669
  ...this.extraProps
630
670
  });
631
671
  }
672
+ getGitBranchesMapping(workspace, dbName) {
673
+ return operationsByTag.database.getGitBranchesMapping({
674
+ pathParams: { workspace, dbName },
675
+ ...this.extraProps
676
+ });
677
+ }
678
+ addGitBranchesEntry(workspace, dbName, body) {
679
+ return operationsByTag.database.addGitBranchesEntry({
680
+ pathParams: { workspace, dbName },
681
+ body,
682
+ ...this.extraProps
683
+ });
684
+ }
685
+ removeGitBranchesEntry(workspace, dbName, gitBranch) {
686
+ return operationsByTag.database.removeGitBranchesEntry({
687
+ pathParams: { workspace, dbName },
688
+ queryParams: { gitBranch },
689
+ ...this.extraProps
690
+ });
691
+ }
692
+ resolveBranch(workspace, dbName, gitBranch) {
693
+ return operationsByTag.database.resolveBranch({
694
+ pathParams: { workspace, dbName },
695
+ queryParams: { gitBranch },
696
+ ...this.extraProps
697
+ });
698
+ }
632
699
  }
633
700
  class BranchApi {
634
701
  constructor(extraProps) {
@@ -646,10 +713,10 @@ class BranchApi {
646
713
  ...this.extraProps
647
714
  });
648
715
  }
649
- createBranch(workspace, database, branch, from = "", options = {}) {
716
+ createBranch(workspace, database, branch, from, options = {}) {
650
717
  return operationsByTag.branch.createBranch({
651
718
  pathParams: { workspace, dbBranchName: `${database}:${branch}` },
652
- queryParams: { from },
719
+ queryParams: isString(from) ? { from } : void 0,
653
720
  body: options,
654
721
  ...this.extraProps
655
722
  });
@@ -831,6 +898,13 @@ class RecordsApi {
831
898
  ...this.extraProps
832
899
  });
833
900
  }
901
+ searchTable(workspace, database, branch, tableName, query) {
902
+ return operationsByTag.records.searchTable({
903
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
904
+ body: query,
905
+ ...this.extraProps
906
+ });
907
+ }
834
908
  searchBranch(workspace, database, branch, query) {
835
909
  return operationsByTag.records.searchBranch({
836
910
  pathParams: { workspace, dbBranchName: `${database}:${branch}` },
@@ -850,43 +924,43 @@ class XataApiPlugin {
850
924
  class XataPlugin {
851
925
  }
852
926
 
853
- var __accessCheck$5 = (obj, member, msg) => {
927
+ var __accessCheck$6 = (obj, member, msg) => {
854
928
  if (!member.has(obj))
855
929
  throw TypeError("Cannot " + msg);
856
930
  };
857
- var __privateGet$4 = (obj, member, getter) => {
858
- __accessCheck$5(obj, member, "read from private field");
931
+ var __privateGet$6 = (obj, member, getter) => {
932
+ __accessCheck$6(obj, member, "read from private field");
859
933
  return getter ? getter.call(obj) : member.get(obj);
860
934
  };
861
- var __privateAdd$5 = (obj, member, value) => {
935
+ var __privateAdd$6 = (obj, member, value) => {
862
936
  if (member.has(obj))
863
937
  throw TypeError("Cannot add the same private member more than once");
864
938
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
865
939
  };
866
- var __privateSet$3 = (obj, member, value, setter) => {
867
- __accessCheck$5(obj, member, "write to private field");
940
+ var __privateSet$5 = (obj, member, value, setter) => {
941
+ __accessCheck$6(obj, member, "write to private field");
868
942
  setter ? setter.call(obj, value) : member.set(obj, value);
869
943
  return value;
870
944
  };
871
- var _query;
945
+ var _query, _page;
872
946
  class Page {
873
947
  constructor(query, meta, records = []) {
874
- __privateAdd$5(this, _query, void 0);
875
- __privateSet$3(this, _query, query);
948
+ __privateAdd$6(this, _query, void 0);
949
+ __privateSet$5(this, _query, query);
876
950
  this.meta = meta;
877
- this.records = records;
951
+ this.records = new RecordArray(this, records);
878
952
  }
879
953
  async nextPage(size, offset) {
880
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
954
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
881
955
  }
882
956
  async previousPage(size, offset) {
883
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
957
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
884
958
  }
885
959
  async firstPage(size, offset) {
886
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
960
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, first: this.meta.page.cursor } });
887
961
  }
888
962
  async lastPage(size, offset) {
889
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
963
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, last: this.meta.page.cursor } });
890
964
  }
891
965
  hasNextPage() {
892
966
  return this.meta.page.more;
@@ -894,50 +968,83 @@ class Page {
894
968
  }
895
969
  _query = new WeakMap();
896
970
  const PAGINATION_MAX_SIZE = 200;
897
- const PAGINATION_DEFAULT_SIZE = 200;
971
+ const PAGINATION_DEFAULT_SIZE = 20;
898
972
  const PAGINATION_MAX_OFFSET = 800;
899
973
  const PAGINATION_DEFAULT_OFFSET = 0;
974
+ function isCursorPaginationOptions(options) {
975
+ return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
976
+ }
977
+ const _RecordArray = class extends Array {
978
+ constructor(page, overrideRecords) {
979
+ super(...overrideRecords ?? page.records);
980
+ __privateAdd$6(this, _page, void 0);
981
+ __privateSet$5(this, _page, page);
982
+ }
983
+ async nextPage(size, offset) {
984
+ const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
985
+ return new _RecordArray(newPage);
986
+ }
987
+ async previousPage(size, offset) {
988
+ const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
989
+ return new _RecordArray(newPage);
990
+ }
991
+ async firstPage(size, offset) {
992
+ const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
993
+ return new _RecordArray(newPage);
994
+ }
995
+ async lastPage(size, offset) {
996
+ const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
997
+ return new _RecordArray(newPage);
998
+ }
999
+ hasNextPage() {
1000
+ return __privateGet$6(this, _page).meta.page.more;
1001
+ }
1002
+ };
1003
+ let RecordArray = _RecordArray;
1004
+ _page = new WeakMap();
900
1005
 
901
- var __accessCheck$4 = (obj, member, msg) => {
1006
+ var __accessCheck$5 = (obj, member, msg) => {
902
1007
  if (!member.has(obj))
903
1008
  throw TypeError("Cannot " + msg);
904
1009
  };
905
- var __privateGet$3 = (obj, member, getter) => {
906
- __accessCheck$4(obj, member, "read from private field");
1010
+ var __privateGet$5 = (obj, member, getter) => {
1011
+ __accessCheck$5(obj, member, "read from private field");
907
1012
  return getter ? getter.call(obj) : member.get(obj);
908
1013
  };
909
- var __privateAdd$4 = (obj, member, value) => {
1014
+ var __privateAdd$5 = (obj, member, value) => {
910
1015
  if (member.has(obj))
911
1016
  throw TypeError("Cannot add the same private member more than once");
912
1017
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
913
1018
  };
914
- var __privateSet$2 = (obj, member, value, setter) => {
915
- __accessCheck$4(obj, member, "write to private field");
1019
+ var __privateSet$4 = (obj, member, value, setter) => {
1020
+ __accessCheck$5(obj, member, "write to private field");
916
1021
  setter ? setter.call(obj, value) : member.set(obj, value);
917
1022
  return value;
918
1023
  };
919
1024
  var _table$1, _repository, _data;
920
1025
  const _Query = class {
921
- 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: {} });
1026
+ constructor(repository, table, data, rawParent) {
1027
+ __privateAdd$5(this, _table$1, void 0);
1028
+ __privateAdd$5(this, _repository, void 0);
1029
+ __privateAdd$5(this, _data, { filter: {} });
925
1030
  this.meta = { page: { cursor: "start", more: true } };
926
- this.records = [];
927
- __privateSet$2(this, _table$1, table);
1031
+ this.records = new RecordArray(this, []);
1032
+ __privateSet$4(this, _table$1, table);
928
1033
  if (repository) {
929
- __privateSet$2(this, _repository, repository);
1034
+ __privateSet$4(this, _repository, repository);
930
1035
  } else {
931
- __privateSet$2(this, _repository, this);
1036
+ __privateSet$4(this, _repository, this);
932
1037
  }
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;
1038
+ const parent = cleanParent(data, rawParent);
1039
+ __privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
1040
+ __privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
1041
+ __privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
1042
+ __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
1043
+ __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1044
+ __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1045
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
1046
+ __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1047
+ __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
941
1048
  this.any = this.any.bind(this);
942
1049
  this.all = this.all.bind(this);
943
1050
  this.not = this.not.bind(this);
@@ -948,75 +1055,88 @@ const _Query = class {
948
1055
  Object.defineProperty(this, "repository", { enumerable: false });
949
1056
  }
950
1057
  getQueryOptions() {
951
- return __privateGet$3(this, _data);
1058
+ return __privateGet$5(this, _data);
1059
+ }
1060
+ key() {
1061
+ const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$5(this, _data);
1062
+ const key = JSON.stringify({ columns, filter, sort, pagination });
1063
+ return toBase64(key);
952
1064
  }
953
1065
  any(...queries) {
954
1066
  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));
1067
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
956
1068
  }
957
1069
  all(...queries) {
958
1070
  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));
1071
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
960
1072
  }
961
1073
  not(...queries) {
962
1074
  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));
1075
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
964
1076
  }
965
1077
  none(...queries) {
966
1078
  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));
1079
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
968
1080
  }
969
1081
  filter(a, b) {
970
1082
  if (arguments.length === 1) {
971
1083
  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));
1084
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1085
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
974
1086
  } 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));
1087
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
1088
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
977
1089
  }
978
1090
  }
979
1091
  sort(column, direction) {
980
- const originalSort = [__privateGet$3(this, _data).sort ?? []].flat();
1092
+ const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
981
1093
  const sort = [...originalSort, { column, direction }];
982
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { sort }, __privateGet$3(this, _data));
1094
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
983
1095
  }
984
1096
  select(columns) {
985
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { columns }, __privateGet$3(this, _data));
1097
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { columns }, __privateGet$5(this, _data));
986
1098
  }
987
1099
  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);
1100
+ const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
1101
+ return __privateGet$5(this, _repository).query(query);
990
1102
  }
991
1103
  async *[Symbol.asyncIterator]() {
992
- for await (const [record] of this.getIterator(1)) {
1104
+ for await (const [record] of this.getIterator({ batchSize: 1 })) {
993
1105
  yield record;
994
1106
  }
995
1107
  }
996
- async *getIterator(chunk, options = {}) {
997
- let offset = 0;
998
- let end = false;
999
- while (!end) {
1000
- const { records, meta } = await this.getPaginated({ ...options, page: { size: chunk, offset } });
1001
- yield records;
1002
- offset += chunk;
1003
- end = !meta.page.more;
1108
+ async *getIterator(options = {}) {
1109
+ const { batchSize = 1 } = options;
1110
+ let page = await this.getPaginated({ ...options, pagination: { size: batchSize, offset: 0 } });
1111
+ let more = page.hasNextPage();
1112
+ yield page.records;
1113
+ while (more) {
1114
+ page = await page.nextPage();
1115
+ more = page.hasNextPage();
1116
+ yield page.records;
1004
1117
  }
1005
1118
  }
1006
1119
  async getMany(options = {}) {
1007
- const { records } = await this.getPaginated(options);
1008
- return records;
1120
+ const page = await this.getPaginated(options);
1121
+ if (page.hasNextPage() && options.pagination?.size === void 0) {
1122
+ console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
1123
+ }
1124
+ return page.records;
1009
1125
  }
1010
- async getAll(chunk = PAGINATION_MAX_SIZE, options = {}) {
1126
+ async getAll(options = {}) {
1127
+ const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
1011
1128
  const results = [];
1012
- for await (const page of this.getIterator(chunk, options)) {
1129
+ for await (const page of this.getIterator({ ...rest, batchSize })) {
1013
1130
  results.push(...page);
1014
1131
  }
1015
1132
  return results;
1016
1133
  }
1017
- async getOne(options = {}) {
1018
- const records = await this.getMany({ ...options, page: { size: 1 } });
1019
- return records[0] || null;
1134
+ async getFirst(options = {}) {
1135
+ const records = await this.getMany({ ...options, pagination: { size: 1 } });
1136
+ return records[0] ?? null;
1137
+ }
1138
+ cache(ttl) {
1139
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1020
1140
  }
1021
1141
  nextPage(size, offset) {
1022
1142
  return this.firstPage(size, offset);
@@ -1025,10 +1145,10 @@ const _Query = class {
1025
1145
  return this.firstPage(size, offset);
1026
1146
  }
1027
1147
  firstPage(size, offset) {
1028
- return this.getPaginated({ page: { size, offset } });
1148
+ return this.getPaginated({ pagination: { size, offset } });
1029
1149
  }
1030
1150
  lastPage(size, offset) {
1031
- return this.getPaginated({ page: { size, offset, before: "end" } });
1151
+ return this.getPaginated({ pagination: { size, offset, before: "end" } });
1032
1152
  }
1033
1153
  hasNextPage() {
1034
1154
  return this.meta.page.more;
@@ -1038,12 +1158,20 @@ let Query = _Query;
1038
1158
  _table$1 = new WeakMap();
1039
1159
  _repository = new WeakMap();
1040
1160
  _data = new WeakMap();
1161
+ function cleanParent(data, parent) {
1162
+ if (isCursorPaginationOptions(data.pagination)) {
1163
+ return { ...parent, sorting: void 0, filter: void 0 };
1164
+ }
1165
+ return parent;
1166
+ }
1041
1167
 
1042
1168
  function isIdentifiable(x) {
1043
1169
  return isObject(x) && isString(x?.id);
1044
1170
  }
1045
1171
  function isXataRecord(x) {
1046
- return isIdentifiable(x) && typeof x?.xata === "object" && typeof x?.xata?.version === "number";
1172
+ const record = x;
1173
+ const metadata = record?.getMetadata();
1174
+ return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
1047
1175
  }
1048
1176
 
1049
1177
  function isSortFilterString(value) {
@@ -1069,169 +1197,229 @@ function buildSortFilter(filter) {
1069
1197
  }
1070
1198
  }
1071
1199
 
1072
- var __accessCheck$3 = (obj, member, msg) => {
1200
+ var __accessCheck$4 = (obj, member, msg) => {
1073
1201
  if (!member.has(obj))
1074
1202
  throw TypeError("Cannot " + msg);
1075
1203
  };
1076
- var __privateGet$2 = (obj, member, getter) => {
1077
- __accessCheck$3(obj, member, "read from private field");
1204
+ var __privateGet$4 = (obj, member, getter) => {
1205
+ __accessCheck$4(obj, member, "read from private field");
1078
1206
  return getter ? getter.call(obj) : member.get(obj);
1079
1207
  };
1080
- var __privateAdd$3 = (obj, member, value) => {
1208
+ var __privateAdd$4 = (obj, member, value) => {
1081
1209
  if (member.has(obj))
1082
1210
  throw TypeError("Cannot add the same private member more than once");
1083
1211
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1084
1212
  };
1085
- var __privateSet$1 = (obj, member, value, setter) => {
1086
- __accessCheck$3(obj, member, "write to private field");
1213
+ var __privateSet$3 = (obj, member, value, setter) => {
1214
+ __accessCheck$4(obj, member, "write to private field");
1087
1215
  setter ? setter.call(obj, value) : member.set(obj, value);
1088
1216
  return value;
1089
1217
  };
1090
1218
  var __privateMethod$2 = (obj, member, method) => {
1091
- __accessCheck$3(obj, member, "access private method");
1219
+ __accessCheck$4(obj, member, "access private method");
1092
1220
  return method;
1093
1221
  };
1094
- var _table, _links, _getFetchProps, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn;
1222
+ var _table, _getFetchProps, _cache, _schema$1, _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, _getSchema$1, getSchema_fn$1;
1095
1223
  class Repository extends Query {
1096
1224
  }
1097
1225
  class RestRepository extends Query {
1098
1226
  constructor(options) {
1099
1227
  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);
1228
+ __privateAdd$4(this, _insertRecordWithoutId);
1229
+ __privateAdd$4(this, _insertRecordWithId);
1230
+ __privateAdd$4(this, _bulkInsertTableRecords);
1231
+ __privateAdd$4(this, _updateRecordWithID);
1232
+ __privateAdd$4(this, _upsertRecordWithID);
1233
+ __privateAdd$4(this, _deleteRecord);
1234
+ __privateAdd$4(this, _invalidateCache);
1235
+ __privateAdd$4(this, _setCacheRecord);
1236
+ __privateAdd$4(this, _getCacheRecord);
1237
+ __privateAdd$4(this, _setCacheQuery);
1238
+ __privateAdd$4(this, _getCacheQuery);
1239
+ __privateAdd$4(this, _getSchema$1);
1240
+ __privateAdd$4(this, _table, void 0);
1241
+ __privateAdd$4(this, _getFetchProps, void 0);
1242
+ __privateAdd$4(this, _cache, void 0);
1243
+ __privateAdd$4(this, _schema$1, void 0);
1244
+ __privateSet$3(this, _table, options.table);
1245
+ __privateSet$3(this, _getFetchProps, options.pluginOptions.getFetchProps);
1112
1246
  this.db = options.db;
1247
+ __privateSet$3(this, _cache, options.pluginOptions.cache);
1113
1248
  }
1114
1249
  async create(a, b) {
1115
1250
  if (Array.isArray(a)) {
1116
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1251
+ if (a.length === 0)
1252
+ return [];
1253
+ const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1254
+ await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1255
+ return records;
1117
1256
  }
1118
1257
  if (isString(a) && isObject(b)) {
1119
1258
  if (a === "")
1120
1259
  throw new Error("The id can't be empty");
1121
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1260
+ const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1261
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1262
+ return record;
1122
1263
  }
1123
1264
  if (isObject(a) && isString(a.id)) {
1124
1265
  if (a.id === "")
1125
1266
  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 });
1267
+ const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1268
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1269
+ return record;
1127
1270
  }
1128
1271
  if (isObject(a)) {
1129
- return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1272
+ const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1273
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1274
+ return record;
1130
1275
  }
1131
1276
  throw new Error("Invalid arguments for create method");
1132
1277
  }
1133
- async read(recordId) {
1134
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1135
- try {
1136
- const response = await getRecord({
1137
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1138
- ...fetchProps
1139
- });
1140
- return initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), response);
1141
- } catch (e) {
1142
- if (isObject(e) && e.status === 404) {
1143
- return null;
1278
+ async read(a) {
1279
+ if (Array.isArray(a)) {
1280
+ if (a.length === 0)
1281
+ return [];
1282
+ return this.getAll({ filter: { id: { $any: a } } });
1283
+ }
1284
+ if (isString(a)) {
1285
+ const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, a);
1286
+ if (cacheRecord)
1287
+ return cacheRecord;
1288
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1289
+ try {
1290
+ const response = await getRecord({
1291
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: a },
1292
+ ...fetchProps
1293
+ });
1294
+ const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1295
+ return initObject(this.db, schema, __privateGet$4(this, _table), response);
1296
+ } catch (e) {
1297
+ if (isObject(e) && e.status === 404) {
1298
+ return null;
1299
+ }
1300
+ throw e;
1144
1301
  }
1145
- throw e;
1146
1302
  }
1147
1303
  }
1148
1304
  async update(a, b) {
1149
1305
  if (Array.isArray(a)) {
1306
+ if (a.length === 0)
1307
+ return [];
1150
1308
  if (a.length > 100) {
1151
1309
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1152
1310
  }
1153
1311
  return Promise.all(a.map((object) => this.update(object)));
1154
1312
  }
1155
1313
  if (isString(a) && isObject(b)) {
1156
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1314
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1315
+ const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1316
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1317
+ return record;
1157
1318
  }
1158
1319
  if (isObject(a) && isString(a.id)) {
1159
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1320
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1321
+ const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1322
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1323
+ return record;
1160
1324
  }
1161
1325
  throw new Error("Invalid arguments for update method");
1162
1326
  }
1163
1327
  async createOrUpdate(a, b) {
1164
1328
  if (Array.isArray(a)) {
1329
+ if (a.length === 0)
1330
+ return [];
1165
1331
  if (a.length > 100) {
1166
1332
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1167
1333
  }
1168
1334
  return Promise.all(a.map((object) => this.createOrUpdate(object)));
1169
1335
  }
1170
1336
  if (isString(a) && isObject(b)) {
1171
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1337
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1338
+ const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1339
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1340
+ return record;
1172
1341
  }
1173
1342
  if (isObject(a) && isString(a.id)) {
1174
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1343
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1344
+ const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1345
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1346
+ return record;
1175
1347
  }
1176
1348
  throw new Error("Invalid arguments for createOrUpdate method");
1177
1349
  }
1178
- async delete(recordId) {
1179
- if (Array.isArray(recordId)) {
1180
- if (recordId.length > 100) {
1350
+ async delete(a) {
1351
+ if (Array.isArray(a)) {
1352
+ if (a.length === 0)
1353
+ return;
1354
+ if (a.length > 100) {
1181
1355
  console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1182
1356
  }
1183
- await Promise.all(recordId.map((id) => this.delete(id)));
1357
+ await Promise.all(a.map((id) => this.delete(id)));
1184
1358
  return;
1185
1359
  }
1186
- if (isString(recordId)) {
1187
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, recordId);
1360
+ if (isString(a)) {
1361
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1362
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1188
1363
  return;
1189
1364
  }
1190
- if (isObject(recordId) && isString(recordId.id)) {
1191
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, recordId.id);
1365
+ if (isObject(a) && isString(a.id)) {
1366
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1367
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1192
1368
  return;
1193
1369
  }
1194
1370
  throw new Error("Invalid arguments for delete method");
1195
1371
  }
1196
1372
  async search(query, options = {}) {
1197
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1198
- const { records } = await searchBranch({
1199
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1200
- body: { tables: [__privateGet$2(this, _table)], query, fuzziness: options.fuzziness },
1373
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1374
+ const { records } = await searchTable({
1375
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1376
+ body: {
1377
+ query,
1378
+ fuzziness: options.fuzziness,
1379
+ highlight: options.highlight,
1380
+ filter: options.filter
1381
+ },
1201
1382
  ...fetchProps
1202
1383
  });
1203
- return records.map((item) => initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), item));
1384
+ const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1385
+ return records.map((item) => initObject(this.db, schema, __privateGet$4(this, _table), item));
1204
1386
  }
1205
1387
  async query(query) {
1388
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1389
+ if (cacheQuery)
1390
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
1206
1391
  const data = query.getQueryOptions();
1207
1392
  const body = {
1208
1393
  filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1209
- sort: data.sort ? buildSortFilter(data.sort) : void 0,
1210
- page: data.page,
1394
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1395
+ page: data.pagination,
1211
1396
  columns: data.columns
1212
1397
  };
1213
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1398
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1214
1399
  const { meta, records: objects } = await queryTable({
1215
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table) },
1400
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1216
1401
  body,
1217
1402
  ...fetchProps
1218
1403
  });
1219
- const records = objects.map((record) => initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), record));
1404
+ const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1405
+ const records = objects.map((record) => initObject(this.db, schema, __privateGet$4(this, _table), record));
1406
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1220
1407
  return new Page(query, meta, records);
1221
1408
  }
1222
1409
  }
1223
1410
  _table = new WeakMap();
1224
- _links = new WeakMap();
1225
1411
  _getFetchProps = new WeakMap();
1412
+ _cache = new WeakMap();
1413
+ _schema$1 = new WeakMap();
1226
1414
  _insertRecordWithoutId = new WeakSet();
1227
1415
  insertRecordWithoutId_fn = async function(object) {
1228
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1416
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1229
1417
  const record = transformObjectLinks(object);
1230
1418
  const response = await insertRecord({
1231
1419
  pathParams: {
1232
1420
  workspace: "{workspaceId}",
1233
1421
  dbBranchName: "{dbBranch}",
1234
- tableName: __privateGet$2(this, _table)
1422
+ tableName: __privateGet$4(this, _table)
1235
1423
  },
1236
1424
  body: record,
1237
1425
  ...fetchProps
@@ -1244,13 +1432,13 @@ insertRecordWithoutId_fn = async function(object) {
1244
1432
  };
1245
1433
  _insertRecordWithId = new WeakSet();
1246
1434
  insertRecordWithId_fn = async function(recordId, object) {
1247
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1435
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1248
1436
  const record = transformObjectLinks(object);
1249
1437
  const response = await insertRecordWithID({
1250
1438
  pathParams: {
1251
1439
  workspace: "{workspaceId}",
1252
1440
  dbBranchName: "{dbBranch}",
1253
- tableName: __privateGet$2(this, _table),
1441
+ tableName: __privateGet$4(this, _table),
1254
1442
  recordId
1255
1443
  },
1256
1444
  body: record,
@@ -1265,10 +1453,10 @@ insertRecordWithId_fn = async function(recordId, object) {
1265
1453
  };
1266
1454
  _bulkInsertTableRecords = new WeakSet();
1267
1455
  bulkInsertTableRecords_fn = async function(objects) {
1268
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1456
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1269
1457
  const records = objects.map((object) => transformObjectLinks(object));
1270
1458
  const response = await bulkInsertTableRecords({
1271
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table) },
1459
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1272
1460
  body: { records },
1273
1461
  ...fetchProps
1274
1462
  });
@@ -1280,10 +1468,10 @@ bulkInsertTableRecords_fn = async function(objects) {
1280
1468
  };
1281
1469
  _updateRecordWithID = new WeakSet();
1282
1470
  updateRecordWithID_fn = async function(recordId, object) {
1283
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1471
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1284
1472
  const record = transformObjectLinks(object);
1285
1473
  const response = await updateRecordWithID({
1286
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1474
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1287
1475
  body: record,
1288
1476
  ...fetchProps
1289
1477
  });
@@ -1294,9 +1482,9 @@ updateRecordWithID_fn = async function(recordId, object) {
1294
1482
  };
1295
1483
  _upsertRecordWithID = new WeakSet();
1296
1484
  upsertRecordWithID_fn = async function(recordId, object) {
1297
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1485
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1298
1486
  const response = await upsertRecordWithID({
1299
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1487
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1300
1488
  body: object,
1301
1489
  ...fetchProps
1302
1490
  });
@@ -1307,12 +1495,63 @@ upsertRecordWithID_fn = async function(recordId, object) {
1307
1495
  };
1308
1496
  _deleteRecord = new WeakSet();
1309
1497
  deleteRecord_fn = async function(recordId) {
1310
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1498
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1311
1499
  await deleteRecord({
1312
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1500
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1313
1501
  ...fetchProps
1314
1502
  });
1315
1503
  };
1504
+ _invalidateCache = new WeakSet();
1505
+ invalidateCache_fn = async function(recordId) {
1506
+ await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1507
+ const cacheItems = await __privateGet$4(this, _cache).getAll();
1508
+ const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1509
+ for (const [key, value] of queries) {
1510
+ const ids = getIds(value);
1511
+ if (ids.includes(recordId))
1512
+ await __privateGet$4(this, _cache).delete(key);
1513
+ }
1514
+ };
1515
+ _setCacheRecord = new WeakSet();
1516
+ setCacheRecord_fn = async function(record) {
1517
+ if (!__privateGet$4(this, _cache).cacheRecords)
1518
+ return;
1519
+ await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
1520
+ };
1521
+ _getCacheRecord = new WeakSet();
1522
+ getCacheRecord_fn = async function(recordId) {
1523
+ if (!__privateGet$4(this, _cache).cacheRecords)
1524
+ return null;
1525
+ return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1526
+ };
1527
+ _setCacheQuery = new WeakSet();
1528
+ setCacheQuery_fn = async function(query, meta, records) {
1529
+ await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
1530
+ };
1531
+ _getCacheQuery = new WeakSet();
1532
+ getCacheQuery_fn = async function(query) {
1533
+ const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
1534
+ const result = await __privateGet$4(this, _cache).get(key);
1535
+ if (!result)
1536
+ return null;
1537
+ const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
1538
+ if (ttl < 0)
1539
+ return null;
1540
+ const hasExpired = result.date.getTime() + ttl < Date.now();
1541
+ return hasExpired ? null : result;
1542
+ };
1543
+ _getSchema$1 = new WeakSet();
1544
+ getSchema_fn$1 = async function() {
1545
+ if (__privateGet$4(this, _schema$1))
1546
+ return __privateGet$4(this, _schema$1);
1547
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1548
+ const { schema } = await getBranchDetails({
1549
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1550
+ ...fetchProps
1551
+ });
1552
+ __privateSet$3(this, _schema$1, schema);
1553
+ return schema;
1554
+ };
1316
1555
  const transformObjectLinks = (object) => {
1317
1556
  return Object.entries(object).reduce((acc, [key, value]) => {
1318
1557
  if (key === "xata")
@@ -1320,15 +1559,34 @@ const transformObjectLinks = (object) => {
1320
1559
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1321
1560
  }, {});
1322
1561
  };
1323
- const initObject = (db, links, table, object) => {
1562
+ const initObject = (db, schema, table, object) => {
1324
1563
  const result = {};
1325
- Object.assign(result, object);
1326
- const tableLinks = links[table] || [];
1327
- for (const link of tableLinks) {
1328
- const [field, linkTable] = link;
1329
- const value = result[field];
1330
- if (value && isObject(value)) {
1331
- result[field] = initObject(db, links, linkTable, value);
1564
+ const { xata, ...rest } = object ?? {};
1565
+ Object.assign(result, rest);
1566
+ const { columns } = schema.tables.find(({ name }) => name === table) ?? {};
1567
+ if (!columns)
1568
+ console.error(`Table ${table} not found in schema`);
1569
+ for (const column of columns ?? []) {
1570
+ const value = result[column.name];
1571
+ switch (column.type) {
1572
+ case "datetime": {
1573
+ const date = value !== void 0 ? new Date(value) : void 0;
1574
+ if (date && isNaN(date.getTime())) {
1575
+ console.error(`Failed to parse date ${value} for field ${column.name}`);
1576
+ } else if (date) {
1577
+ result[column.name] = date;
1578
+ }
1579
+ break;
1580
+ }
1581
+ case "link": {
1582
+ const linkTable = column.link?.table;
1583
+ if (!linkTable) {
1584
+ console.error(`Failed to parse link for field ${column.name}`);
1585
+ } else if (isObject(value)) {
1586
+ result[column.name] = initObject(db, schema, linkTable, value);
1587
+ }
1588
+ break;
1589
+ }
1332
1590
  }
1333
1591
  }
1334
1592
  result.read = function() {
@@ -1340,12 +1598,74 @@ const initObject = (db, links, table, object) => {
1340
1598
  result.delete = function() {
1341
1599
  return db[table].delete(result["id"]);
1342
1600
  };
1343
- for (const prop of ["read", "update", "delete"]) {
1601
+ result.getMetadata = function() {
1602
+ return xata;
1603
+ };
1604
+ for (const prop of ["read", "update", "delete", "getMetadata"]) {
1344
1605
  Object.defineProperty(result, prop, { enumerable: false });
1345
1606
  }
1346
1607
  Object.freeze(result);
1347
1608
  return result;
1348
1609
  };
1610
+ function getIds(value) {
1611
+ if (Array.isArray(value)) {
1612
+ return value.map((item) => getIds(item)).flat();
1613
+ }
1614
+ if (!isObject(value))
1615
+ return [];
1616
+ const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1617
+ return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
1618
+ }
1619
+
1620
+ var __accessCheck$3 = (obj, member, msg) => {
1621
+ if (!member.has(obj))
1622
+ throw TypeError("Cannot " + msg);
1623
+ };
1624
+ var __privateGet$3 = (obj, member, getter) => {
1625
+ __accessCheck$3(obj, member, "read from private field");
1626
+ return getter ? getter.call(obj) : member.get(obj);
1627
+ };
1628
+ var __privateAdd$3 = (obj, member, value) => {
1629
+ if (member.has(obj))
1630
+ throw TypeError("Cannot add the same private member more than once");
1631
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1632
+ };
1633
+ var __privateSet$2 = (obj, member, value, setter) => {
1634
+ __accessCheck$3(obj, member, "write to private field");
1635
+ setter ? setter.call(obj, value) : member.set(obj, value);
1636
+ return value;
1637
+ };
1638
+ var _map;
1639
+ class SimpleCache {
1640
+ constructor(options = {}) {
1641
+ __privateAdd$3(this, _map, void 0);
1642
+ __privateSet$2(this, _map, /* @__PURE__ */ new Map());
1643
+ this.capacity = options.max ?? 500;
1644
+ this.cacheRecords = options.cacheRecords ?? true;
1645
+ this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1646
+ }
1647
+ async getAll() {
1648
+ return Object.fromEntries(__privateGet$3(this, _map));
1649
+ }
1650
+ async get(key) {
1651
+ return __privateGet$3(this, _map).get(key) ?? null;
1652
+ }
1653
+ async set(key, value) {
1654
+ await this.delete(key);
1655
+ __privateGet$3(this, _map).set(key, value);
1656
+ if (__privateGet$3(this, _map).size > this.capacity) {
1657
+ const leastRecentlyUsed = __privateGet$3(this, _map).keys().next().value;
1658
+ await this.delete(leastRecentlyUsed);
1659
+ }
1660
+ }
1661
+ async delete(key) {
1662
+ __privateGet$3(this, _map).delete(key);
1663
+ }
1664
+ async clear() {
1665
+ return __privateGet$3(this, _map).clear();
1666
+ }
1667
+ }
1668
+ _map = new WeakMap();
1349
1669
 
1350
1670
  const gt = (value) => ({ $gt: value });
1351
1671
  const ge = (value) => ({ $ge: value });
@@ -1370,7 +1690,7 @@ var __accessCheck$2 = (obj, member, msg) => {
1370
1690
  if (!member.has(obj))
1371
1691
  throw TypeError("Cannot " + msg);
1372
1692
  };
1373
- var __privateGet$1 = (obj, member, getter) => {
1693
+ var __privateGet$2 = (obj, member, getter) => {
1374
1694
  __accessCheck$2(obj, member, "read from private field");
1375
1695
  return getter ? getter.call(obj) : member.get(obj);
1376
1696
  };
@@ -1381,26 +1701,24 @@ var __privateAdd$2 = (obj, member, value) => {
1381
1701
  };
1382
1702
  var _tables;
1383
1703
  class SchemaPlugin extends XataPlugin {
1384
- constructor(links, tableNames) {
1704
+ constructor(tableNames) {
1385
1705
  super();
1386
- this.links = links;
1387
1706
  this.tableNames = tableNames;
1388
1707
  __privateAdd$2(this, _tables, {});
1389
1708
  }
1390
- build(options) {
1391
- const { getFetchProps } = options;
1392
- const links = this.links;
1709
+ build(pluginOptions) {
1393
1710
  const db = new Proxy({}, {
1394
1711
  get: (_target, table) => {
1395
1712
  if (!isString(table))
1396
1713
  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 });
1399
- return __privateGet$1(this, _tables)[table];
1714
+ if (__privateGet$2(this, _tables)[table] === void 0) {
1715
+ __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table });
1716
+ }
1717
+ return __privateGet$2(this, _tables)[table];
1400
1718
  }
1401
1719
  });
1402
1720
  for (const table of this.tableNames ?? []) {
1403
- db[table] = new RestRepository({ db, getFetchProps, table, links });
1721
+ db[table] = new RestRepository({ db, pluginOptions, table });
1404
1722
  }
1405
1723
  return db;
1406
1724
  }
@@ -1411,55 +1729,80 @@ var __accessCheck$1 = (obj, member, msg) => {
1411
1729
  if (!member.has(obj))
1412
1730
  throw TypeError("Cannot " + msg);
1413
1731
  };
1732
+ var __privateGet$1 = (obj, member, getter) => {
1733
+ __accessCheck$1(obj, member, "read from private field");
1734
+ return getter ? getter.call(obj) : member.get(obj);
1735
+ };
1414
1736
  var __privateAdd$1 = (obj, member, value) => {
1415
1737
  if (member.has(obj))
1416
1738
  throw TypeError("Cannot add the same private member more than once");
1417
1739
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1418
1740
  };
1741
+ var __privateSet$1 = (obj, member, value, setter) => {
1742
+ __accessCheck$1(obj, member, "write to private field");
1743
+ setter ? setter.call(obj, value) : member.set(obj, value);
1744
+ return value;
1745
+ };
1419
1746
  var __privateMethod$1 = (obj, member, method) => {
1420
1747
  __accessCheck$1(obj, member, "access private method");
1421
1748
  return method;
1422
1749
  };
1423
- var _search, search_fn;
1750
+ var _schema, _search, search_fn, _getSchema, getSchema_fn;
1424
1751
  class SearchPlugin extends XataPlugin {
1425
- constructor(db, links) {
1752
+ constructor(db) {
1426
1753
  super();
1427
1754
  this.db = db;
1428
- this.links = links;
1429
1755
  __privateAdd$1(this, _search);
1756
+ __privateAdd$1(this, _getSchema);
1757
+ __privateAdd$1(this, _schema, void 0);
1430
1758
  }
1431
1759
  build({ getFetchProps }) {
1432
1760
  return {
1433
1761
  all: async (query, options = {}) => {
1434
1762
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
1763
+ const schema = await __privateMethod$1(this, _getSchema, getSchema_fn).call(this, getFetchProps);
1435
1764
  return records.map((record) => {
1436
1765
  const { table = "orphan" } = record.xata;
1437
- return { table, record: initObject(this.db, this.links, table, record) };
1766
+ return { table, record: initObject(this.db, schema, table, record) };
1438
1767
  });
1439
1768
  },
1440
1769
  byTable: async (query, options = {}) => {
1441
1770
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
1771
+ const schema = await __privateMethod$1(this, _getSchema, getSchema_fn).call(this, getFetchProps);
1442
1772
  return records.reduce((acc, record) => {
1443
1773
  const { table = "orphan" } = record.xata;
1444
1774
  const items = acc[table] ?? [];
1445
- const item = initObject(this.db, this.links, table, record);
1775
+ const item = initObject(this.db, schema, table, record);
1446
1776
  return { ...acc, [table]: [...items, item] };
1447
1777
  }, {});
1448
1778
  }
1449
1779
  };
1450
1780
  }
1451
1781
  }
1782
+ _schema = new WeakMap();
1452
1783
  _search = new WeakSet();
1453
1784
  search_fn = async function(query, options, getFetchProps) {
1454
1785
  const fetchProps = await getFetchProps();
1455
- const { tables, fuzziness } = options ?? {};
1786
+ const { tables, fuzziness, highlight } = options ?? {};
1456
1787
  const { records } = await searchBranch({
1457
1788
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1458
- body: { tables, query, fuzziness },
1789
+ body: { tables, query, fuzziness, highlight },
1459
1790
  ...fetchProps
1460
1791
  });
1461
1792
  return records;
1462
1793
  };
1794
+ _getSchema = new WeakSet();
1795
+ getSchema_fn = async function(getFetchProps) {
1796
+ if (__privateGet$1(this, _schema))
1797
+ return __privateGet$1(this, _schema);
1798
+ const fetchProps = await getFetchProps();
1799
+ const { schema } = await getBranchDetails({
1800
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1801
+ ...fetchProps
1802
+ });
1803
+ __privateSet$1(this, _schema, schema);
1804
+ return schema;
1805
+ };
1463
1806
 
1464
1807
  const isBranchStrategyBuilder = (strategy) => {
1465
1808
  return typeof strategy === "function";
@@ -1471,30 +1814,39 @@ const envBranchNames = [
1471
1814
  "CF_PAGES_BRANCH",
1472
1815
  "BRANCH"
1473
1816
  ];
1474
- const defaultBranch = "main";
1475
1817
  async function getCurrentBranchName(options) {
1476
- const env = await getBranchByEnvVariable();
1477
- if (env)
1478
- return env;
1479
- const branch = await getGitBranch();
1480
- if (!branch)
1481
- return defaultBranch;
1482
- const details = await getDatabaseBranch(branch, options);
1483
- if (details)
1484
- return branch;
1485
- return defaultBranch;
1818
+ const env = getBranchByEnvVariable();
1819
+ if (env) {
1820
+ const details = await getDatabaseBranch(env, options);
1821
+ if (details)
1822
+ return env;
1823
+ console.warn(`Branch ${env} not found in Xata. Ignoring...`);
1824
+ }
1825
+ const gitBranch = await getGitBranch();
1826
+ return resolveXataBranch(gitBranch, options);
1486
1827
  }
1487
1828
  async function getCurrentBranchDetails(options) {
1488
- const env = await getBranchByEnvVariable();
1489
- if (env)
1490
- return getDatabaseBranch(env, options);
1491
- const branch = await getGitBranch();
1492
- if (!branch)
1493
- return getDatabaseBranch(defaultBranch, options);
1494
- const details = await getDatabaseBranch(branch, options);
1495
- if (details)
1496
- return details;
1497
- return getDatabaseBranch(defaultBranch, options);
1829
+ const branch = await getCurrentBranchName(options);
1830
+ return getDatabaseBranch(branch, options);
1831
+ }
1832
+ async function resolveXataBranch(gitBranch, options) {
1833
+ const databaseURL = options?.databaseURL || getDatabaseURL();
1834
+ const apiKey = options?.apiKey || getAPIKey();
1835
+ if (!databaseURL)
1836
+ throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
1837
+ if (!apiKey)
1838
+ throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
1839
+ const [protocol, , host, , dbName] = databaseURL.split("/");
1840
+ const [workspace] = host.split(".");
1841
+ const { branch } = await resolveBranch({
1842
+ apiKey,
1843
+ apiUrl: databaseURL,
1844
+ fetchImpl: getFetchImplementation(options?.fetchImpl),
1845
+ workspacesApiUrl: `${protocol}//${host}`,
1846
+ pathParams: { dbName, workspace },
1847
+ queryParams: { gitBranch, fallbackBranch: getEnvVariable("XATA_FALLBACK_BRANCH") }
1848
+ });
1849
+ return branch;
1498
1850
  }
1499
1851
  async function getDatabaseBranch(branch, options) {
1500
1852
  const databaseURL = options?.databaseURL || getDatabaseURL();
@@ -1568,22 +1920,24 @@ var __privateMethod = (obj, member, method) => {
1568
1920
  const buildClient = (plugins) => {
1569
1921
  var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
1570
1922
  return _a = class {
1571
- constructor(options = {}, links, tables) {
1923
+ constructor(options = {}, tables) {
1572
1924
  __privateAdd(this, _parseOptions);
1573
1925
  __privateAdd(this, _getFetchProps);
1574
1926
  __privateAdd(this, _evaluateBranch);
1575
1927
  __privateAdd(this, _branch, void 0);
1576
1928
  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
- });
1929
+ const pluginOptions = {
1930
+ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
1931
+ cache: safeOptions.cache
1932
+ };
1933
+ const db = new SchemaPlugin(tables).build(pluginOptions);
1934
+ const search = new SearchPlugin(db).build(pluginOptions);
1581
1935
  this.db = db;
1582
1936
  this.search = search;
1583
1937
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
1584
- if (!namespace)
1938
+ if (namespace === void 0)
1585
1939
  continue;
1586
- const result = namespace.build({ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions) });
1940
+ const result = namespace.build(pluginOptions);
1587
1941
  if (result instanceof Promise) {
1588
1942
  void result.then((namespace2) => {
1589
1943
  this[key] = namespace2;
@@ -1597,11 +1951,12 @@ const buildClient = (plugins) => {
1597
1951
  const fetch = getFetchImplementation(options?.fetch);
1598
1952
  const databaseURL = options?.databaseURL || getDatabaseURL();
1599
1953
  const apiKey = options?.apiKey || getAPIKey();
1600
- const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
1954
+ const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
1955
+ const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
1601
1956
  if (!databaseURL || !apiKey) {
1602
1957
  throw new Error("Options databaseURL and apiKey are required");
1603
1958
  }
1604
- return { fetch, databaseURL, apiKey, branch };
1959
+ return { fetch, databaseURL, apiKey, branch, cache };
1605
1960
  }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
1606
1961
  fetch,
1607
1962
  apiKey,
@@ -1624,7 +1979,7 @@ const buildClient = (plugins) => {
1624
1979
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
1625
1980
  if (__privateGet(this, _branch))
1626
1981
  return __privateGet(this, _branch);
1627
- if (!param)
1982
+ if (param === void 0)
1628
1983
  return void 0;
1629
1984
  const strategies = Array.isArray(param) ? [...param] : [param];
1630
1985
  const evaluateBranch = async (strategy) => {
@@ -1649,5 +2004,5 @@ class XataError extends Error {
1649
2004
  }
1650
2005
  }
1651
2006
 
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 };
2007
+ export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, 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, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
1653
2008
  //# sourceMappingURL=index.mjs.map