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