@xata.io/client 0.0.0-alpha.vf6d8daa → 0.0.0-alpha.vf7b5320
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 +24 -0
- package/dist/index.cjs +260 -137
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +223 -22
- package/dist/index.mjs +257 -138
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
@@ -38,7 +38,10 @@ function getEnvVariable(name) {
|
|
38
38
|
}
|
39
39
|
async function getGitBranch() {
|
40
40
|
try {
|
41
|
-
|
41
|
+
if (typeof require === "function") {
|
42
|
+
const req = require;
|
43
|
+
return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
|
44
|
+
}
|
42
45
|
} catch (err) {
|
43
46
|
}
|
44
47
|
try {
|
@@ -252,6 +255,14 @@ const deleteDatabase = (variables) => fetch$1({
|
|
252
255
|
method: "delete",
|
253
256
|
...variables
|
254
257
|
});
|
258
|
+
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
259
|
+
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
260
|
+
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
261
|
+
const resolveBranch = (variables) => fetch$1({
|
262
|
+
url: "/dbs/{dbName}/resolveBranch",
|
263
|
+
method: "get",
|
264
|
+
...variables
|
265
|
+
});
|
255
266
|
const getBranchDetails = (variables) => fetch$1({
|
256
267
|
url: "/db/{dbBranchName}",
|
257
268
|
method: "get",
|
@@ -380,7 +391,15 @@ const operationsByTag = {
|
|
380
391
|
resendWorkspaceMemberInvite,
|
381
392
|
acceptWorkspaceMemberInvite
|
382
393
|
},
|
383
|
-
database: {
|
394
|
+
database: {
|
395
|
+
getDatabaseList,
|
396
|
+
createDatabase,
|
397
|
+
deleteDatabase,
|
398
|
+
getGitBranchesMapping,
|
399
|
+
addGitBranchesEntry,
|
400
|
+
removeGitBranchesEntry,
|
401
|
+
resolveBranch
|
402
|
+
},
|
384
403
|
branch: {
|
385
404
|
getBranchList,
|
386
405
|
getBranchDetails,
|
@@ -447,7 +466,7 @@ var __accessCheck$7 = (obj, member, msg) => {
|
|
447
466
|
if (!member.has(obj))
|
448
467
|
throw TypeError("Cannot " + msg);
|
449
468
|
};
|
450
|
-
var __privateGet$
|
469
|
+
var __privateGet$7 = (obj, member, getter) => {
|
451
470
|
__accessCheck$7(obj, member, "read from private field");
|
452
471
|
return getter ? getter.call(obj) : member.get(obj);
|
453
472
|
};
|
@@ -456,7 +475,7 @@ var __privateAdd$7 = (obj, member, value) => {
|
|
456
475
|
throw TypeError("Cannot add the same private member more than once");
|
457
476
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
458
477
|
};
|
459
|
-
var __privateSet$
|
478
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
460
479
|
__accessCheck$7(obj, member, "write to private field");
|
461
480
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
462
481
|
return value;
|
@@ -471,7 +490,7 @@ class XataApiClient {
|
|
471
490
|
if (!apiKey) {
|
472
491
|
throw new Error("Could not resolve a valid apiKey");
|
473
492
|
}
|
474
|
-
__privateSet$
|
493
|
+
__privateSet$6(this, _extraProps, {
|
475
494
|
apiUrl: getHostUrl(provider, "main"),
|
476
495
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
477
496
|
fetchImpl: getFetchImplementation(options.fetch),
|
@@ -479,34 +498,34 @@ class XataApiClient {
|
|
479
498
|
});
|
480
499
|
}
|
481
500
|
get user() {
|
482
|
-
if (!__privateGet$
|
483
|
-
__privateGet$
|
484
|
-
return __privateGet$
|
501
|
+
if (!__privateGet$7(this, _namespaces).user)
|
502
|
+
__privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
|
503
|
+
return __privateGet$7(this, _namespaces).user;
|
485
504
|
}
|
486
505
|
get workspaces() {
|
487
|
-
if (!__privateGet$
|
488
|
-
__privateGet$
|
489
|
-
return __privateGet$
|
506
|
+
if (!__privateGet$7(this, _namespaces).workspaces)
|
507
|
+
__privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
|
508
|
+
return __privateGet$7(this, _namespaces).workspaces;
|
490
509
|
}
|
491
510
|
get databases() {
|
492
|
-
if (!__privateGet$
|
493
|
-
__privateGet$
|
494
|
-
return __privateGet$
|
511
|
+
if (!__privateGet$7(this, _namespaces).databases)
|
512
|
+
__privateGet$7(this, _namespaces).databases = new DatabaseApi(__privateGet$7(this, _extraProps));
|
513
|
+
return __privateGet$7(this, _namespaces).databases;
|
495
514
|
}
|
496
515
|
get branches() {
|
497
|
-
if (!__privateGet$
|
498
|
-
__privateGet$
|
499
|
-
return __privateGet$
|
516
|
+
if (!__privateGet$7(this, _namespaces).branches)
|
517
|
+
__privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
|
518
|
+
return __privateGet$7(this, _namespaces).branches;
|
500
519
|
}
|
501
520
|
get tables() {
|
502
|
-
if (!__privateGet$
|
503
|
-
__privateGet$
|
504
|
-
return __privateGet$
|
521
|
+
if (!__privateGet$7(this, _namespaces).tables)
|
522
|
+
__privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
|
523
|
+
return __privateGet$7(this, _namespaces).tables;
|
505
524
|
}
|
506
525
|
get records() {
|
507
|
-
if (!__privateGet$
|
508
|
-
__privateGet$
|
509
|
-
return __privateGet$
|
526
|
+
if (!__privateGet$7(this, _namespaces).records)
|
527
|
+
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
528
|
+
return __privateGet$7(this, _namespaces).records;
|
510
529
|
}
|
511
530
|
}
|
512
531
|
_extraProps = new WeakMap();
|
@@ -640,6 +659,33 @@ class DatabaseApi {
|
|
640
659
|
...this.extraProps
|
641
660
|
});
|
642
661
|
}
|
662
|
+
getGitBranchesMapping(workspace, dbName) {
|
663
|
+
return operationsByTag.database.getGitBranchesMapping({
|
664
|
+
pathParams: { workspace, dbName },
|
665
|
+
...this.extraProps
|
666
|
+
});
|
667
|
+
}
|
668
|
+
addGitBranchesEntry(workspace, dbName, body) {
|
669
|
+
return operationsByTag.database.addGitBranchesEntry({
|
670
|
+
pathParams: { workspace, dbName },
|
671
|
+
body,
|
672
|
+
...this.extraProps
|
673
|
+
});
|
674
|
+
}
|
675
|
+
removeGitBranchesEntry(workspace, dbName, gitBranch) {
|
676
|
+
return operationsByTag.database.removeGitBranchesEntry({
|
677
|
+
pathParams: { workspace, dbName },
|
678
|
+
queryParams: { gitBranch },
|
679
|
+
...this.extraProps
|
680
|
+
});
|
681
|
+
}
|
682
|
+
resolveBranch(workspace, dbName, gitBranch) {
|
683
|
+
return operationsByTag.database.resolveBranch({
|
684
|
+
pathParams: { workspace, dbName },
|
685
|
+
queryParams: { gitBranch },
|
686
|
+
...this.extraProps
|
687
|
+
});
|
688
|
+
}
|
643
689
|
}
|
644
690
|
class BranchApi {
|
645
691
|
constructor(extraProps) {
|
@@ -865,7 +911,7 @@ var __accessCheck$6 = (obj, member, msg) => {
|
|
865
911
|
if (!member.has(obj))
|
866
912
|
throw TypeError("Cannot " + msg);
|
867
913
|
};
|
868
|
-
var __privateGet$
|
914
|
+
var __privateGet$6 = (obj, member, getter) => {
|
869
915
|
__accessCheck$6(obj, member, "read from private field");
|
870
916
|
return getter ? getter.call(obj) : member.get(obj);
|
871
917
|
};
|
@@ -874,7 +920,7 @@ var __privateAdd$6 = (obj, member, value) => {
|
|
874
920
|
throw TypeError("Cannot add the same private member more than once");
|
875
921
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
876
922
|
};
|
877
|
-
var __privateSet$
|
923
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
878
924
|
__accessCheck$6(obj, member, "write to private field");
|
879
925
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
880
926
|
return value;
|
@@ -883,21 +929,21 @@ var _query;
|
|
883
929
|
class Page {
|
884
930
|
constructor(query, meta, records = []) {
|
885
931
|
__privateAdd$6(this, _query, void 0);
|
886
|
-
__privateSet$
|
932
|
+
__privateSet$5(this, _query, query);
|
887
933
|
this.meta = meta;
|
888
934
|
this.records = records;
|
889
935
|
}
|
890
936
|
async nextPage(size, offset) {
|
891
|
-
return __privateGet$
|
937
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
892
938
|
}
|
893
939
|
async previousPage(size, offset) {
|
894
|
-
return __privateGet$
|
940
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
895
941
|
}
|
896
942
|
async firstPage(size, offset) {
|
897
|
-
return __privateGet$
|
943
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, first: this.meta.page.cursor } });
|
898
944
|
}
|
899
945
|
async lastPage(size, offset) {
|
900
|
-
return __privateGet$
|
946
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, last: this.meta.page.cursor } });
|
901
947
|
}
|
902
948
|
hasNextPage() {
|
903
949
|
return this.meta.page.more;
|
@@ -913,7 +959,7 @@ var __accessCheck$5 = (obj, member, msg) => {
|
|
913
959
|
if (!member.has(obj))
|
914
960
|
throw TypeError("Cannot " + msg);
|
915
961
|
};
|
916
|
-
var __privateGet$
|
962
|
+
var __privateGet$5 = (obj, member, getter) => {
|
917
963
|
__accessCheck$5(obj, member, "read from private field");
|
918
964
|
return getter ? getter.call(obj) : member.get(obj);
|
919
965
|
};
|
@@ -922,7 +968,7 @@ var __privateAdd$5 = (obj, member, value) => {
|
|
922
968
|
throw TypeError("Cannot add the same private member more than once");
|
923
969
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
924
970
|
};
|
925
|
-
var __privateSet$
|
971
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
926
972
|
__accessCheck$5(obj, member, "write to private field");
|
927
973
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
928
974
|
return value;
|
@@ -935,21 +981,21 @@ const _Query = class {
|
|
935
981
|
__privateAdd$5(this, _data, { filter: {} });
|
936
982
|
this.meta = { page: { cursor: "start", more: true } };
|
937
983
|
this.records = [];
|
938
|
-
__privateSet$
|
984
|
+
__privateSet$4(this, _table$1, table);
|
939
985
|
if (repository) {
|
940
|
-
__privateSet$
|
986
|
+
__privateSet$4(this, _repository, repository);
|
941
987
|
} else {
|
942
|
-
__privateSet$
|
988
|
+
__privateSet$4(this, _repository, this);
|
943
989
|
}
|
944
|
-
__privateGet$
|
945
|
-
__privateGet$
|
946
|
-
__privateGet$
|
947
|
-
__privateGet$
|
948
|
-
__privateGet$
|
949
|
-
__privateGet$
|
950
|
-
__privateGet$
|
951
|
-
__privateGet$
|
952
|
-
__privateGet$
|
990
|
+
__privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
991
|
+
__privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
|
992
|
+
__privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
|
993
|
+
__privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
|
994
|
+
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
995
|
+
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
996
|
+
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
|
997
|
+
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
998
|
+
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
953
999
|
this.any = this.any.bind(this);
|
954
1000
|
this.all = this.all.bind(this);
|
955
1001
|
this.not = this.not.bind(this);
|
@@ -960,50 +1006,50 @@ const _Query = class {
|
|
960
1006
|
Object.defineProperty(this, "repository", { enumerable: false });
|
961
1007
|
}
|
962
1008
|
getQueryOptions() {
|
963
|
-
return __privateGet$
|
1009
|
+
return __privateGet$5(this, _data);
|
964
1010
|
}
|
965
1011
|
key() {
|
966
|
-
const { columns = [], filter = {}, sort = [],
|
967
|
-
const key = JSON.stringify({ columns, filter, sort,
|
1012
|
+
const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$5(this, _data);
|
1013
|
+
const key = JSON.stringify({ columns, filter, sort, pagination });
|
968
1014
|
return toBase64(key);
|
969
1015
|
}
|
970
1016
|
any(...queries) {
|
971
1017
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
972
|
-
return new _Query(__privateGet$
|
1018
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
973
1019
|
}
|
974
1020
|
all(...queries) {
|
975
1021
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
976
|
-
return new _Query(__privateGet$
|
1022
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
977
1023
|
}
|
978
1024
|
not(...queries) {
|
979
1025
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
980
|
-
return new _Query(__privateGet$
|
1026
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
981
1027
|
}
|
982
1028
|
none(...queries) {
|
983
1029
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
984
|
-
return new _Query(__privateGet$
|
1030
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
985
1031
|
}
|
986
1032
|
filter(a, b) {
|
987
1033
|
if (arguments.length === 1) {
|
988
1034
|
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
989
|
-
const $all = compact([__privateGet$
|
990
|
-
return new _Query(__privateGet$
|
1035
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1036
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
991
1037
|
} else {
|
992
|
-
const $all = compact([__privateGet$
|
993
|
-
return new _Query(__privateGet$
|
1038
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
|
1039
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
994
1040
|
}
|
995
1041
|
}
|
996
1042
|
sort(column, direction) {
|
997
|
-
const originalSort = [__privateGet$
|
1043
|
+
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
998
1044
|
const sort = [...originalSort, { column, direction }];
|
999
|
-
return new _Query(__privateGet$
|
1045
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1000
1046
|
}
|
1001
1047
|
select(columns) {
|
1002
|
-
return new _Query(__privateGet$
|
1048
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { columns }, __privateGet$5(this, _data));
|
1003
1049
|
}
|
1004
1050
|
getPaginated(options = {}) {
|
1005
|
-
const query = new _Query(__privateGet$
|
1006
|
-
return __privateGet$
|
1051
|
+
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
1052
|
+
return __privateGet$5(this, _repository).query(query);
|
1007
1053
|
}
|
1008
1054
|
async *[Symbol.asyncIterator]() {
|
1009
1055
|
for await (const [record] of this.getIterator(1)) {
|
@@ -1014,7 +1060,7 @@ const _Query = class {
|
|
1014
1060
|
let offset = 0;
|
1015
1061
|
let end = false;
|
1016
1062
|
while (!end) {
|
1017
|
-
const { records, meta } = await this.getPaginated({ ...options,
|
1063
|
+
const { records, meta } = await this.getPaginated({ ...options, pagination: { size: chunk, offset } });
|
1018
1064
|
yield records;
|
1019
1065
|
offset += chunk;
|
1020
1066
|
end = !meta.page.more;
|
@@ -1032,9 +1078,12 @@ const _Query = class {
|
|
1032
1078
|
return results;
|
1033
1079
|
}
|
1034
1080
|
async getFirst(options = {}) {
|
1035
|
-
const records = await this.getMany({ ...options,
|
1081
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1036
1082
|
return records[0] || null;
|
1037
1083
|
}
|
1084
|
+
cache(ttl) {
|
1085
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1086
|
+
}
|
1038
1087
|
nextPage(size, offset) {
|
1039
1088
|
return this.firstPage(size, offset);
|
1040
1089
|
}
|
@@ -1042,10 +1091,10 @@ const _Query = class {
|
|
1042
1091
|
return this.firstPage(size, offset);
|
1043
1092
|
}
|
1044
1093
|
firstPage(size, offset) {
|
1045
|
-
return this.getPaginated({
|
1094
|
+
return this.getPaginated({ pagination: { size, offset } });
|
1046
1095
|
}
|
1047
1096
|
lastPage(size, offset) {
|
1048
|
-
return this.getPaginated({
|
1097
|
+
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
1049
1098
|
}
|
1050
1099
|
hasNextPage() {
|
1051
1100
|
return this.meta.page.more;
|
@@ -1090,7 +1139,7 @@ var __accessCheck$4 = (obj, member, msg) => {
|
|
1090
1139
|
if (!member.has(obj))
|
1091
1140
|
throw TypeError("Cannot " + msg);
|
1092
1141
|
};
|
1093
|
-
var __privateGet$
|
1142
|
+
var __privateGet$4 = (obj, member, getter) => {
|
1094
1143
|
__accessCheck$4(obj, member, "read from private field");
|
1095
1144
|
return getter ? getter.call(obj) : member.get(obj);
|
1096
1145
|
};
|
@@ -1099,7 +1148,7 @@ var __privateAdd$4 = (obj, member, value) => {
|
|
1099
1148
|
throw TypeError("Cannot add the same private member more than once");
|
1100
1149
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1101
1150
|
};
|
1102
|
-
var __privateSet$
|
1151
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
1103
1152
|
__accessCheck$4(obj, member, "write to private field");
|
1104
1153
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1105
1154
|
return value;
|
@@ -1108,7 +1157,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1108
1157
|
__accessCheck$4(obj, member, "access private method");
|
1109
1158
|
return method;
|
1110
1159
|
};
|
1111
|
-
var _table,
|
1160
|
+
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;
|
1112
1161
|
class Repository extends Query {
|
1113
1162
|
}
|
1114
1163
|
class RestRepository extends Query {
|
@@ -1125,14 +1174,15 @@ class RestRepository extends Query {
|
|
1125
1174
|
__privateAdd$4(this, _getCacheRecord);
|
1126
1175
|
__privateAdd$4(this, _setCacheQuery);
|
1127
1176
|
__privateAdd$4(this, _getCacheQuery);
|
1177
|
+
__privateAdd$4(this, _getSchema$1);
|
1128
1178
|
__privateAdd$4(this, _table, void 0);
|
1129
|
-
__privateAdd$4(this, _links, void 0);
|
1130
1179
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1131
|
-
|
1132
|
-
|
1133
|
-
__privateSet$
|
1180
|
+
__privateAdd$4(this, _cache, void 0);
|
1181
|
+
__privateAdd$4(this, _schema$1, void 0);
|
1182
|
+
__privateSet$3(this, _table, options.table);
|
1183
|
+
__privateSet$3(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1134
1184
|
this.db = options.db;
|
1135
|
-
this
|
1185
|
+
__privateSet$3(this, _cache, options.pluginOptions.cache);
|
1136
1186
|
}
|
1137
1187
|
async create(a, b) {
|
1138
1188
|
if (Array.isArray(a)) {
|
@@ -1165,13 +1215,14 @@ class RestRepository extends Query {
|
|
1165
1215
|
const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, recordId);
|
1166
1216
|
if (cacheRecord)
|
1167
1217
|
return cacheRecord;
|
1168
|
-
const fetchProps = await __privateGet$
|
1218
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1169
1219
|
try {
|
1170
1220
|
const response = await getRecord({
|
1171
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$
|
1221
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1172
1222
|
...fetchProps
|
1173
1223
|
});
|
1174
|
-
|
1224
|
+
const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
|
1225
|
+
return initObject(this.db, schema, __privateGet$4(this, _table), response);
|
1175
1226
|
} catch (e) {
|
1176
1227
|
if (isObject(e) && e.status === 404) {
|
1177
1228
|
return null;
|
@@ -1242,13 +1293,14 @@ class RestRepository extends Query {
|
|
1242
1293
|
throw new Error("Invalid arguments for delete method");
|
1243
1294
|
}
|
1244
1295
|
async search(query, options = {}) {
|
1245
|
-
const fetchProps = await __privateGet$
|
1296
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1246
1297
|
const { records } = await searchBranch({
|
1247
1298
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1248
|
-
body: { tables: [__privateGet$
|
1299
|
+
body: { tables: [__privateGet$4(this, _table)], query, fuzziness: options.fuzziness },
|
1249
1300
|
...fetchProps
|
1250
1301
|
});
|
1251
|
-
|
1302
|
+
const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
|
1303
|
+
return records.map((item) => initObject(this.db, schema, __privateGet$4(this, _table), item));
|
1252
1304
|
}
|
1253
1305
|
async query(query) {
|
1254
1306
|
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
@@ -1258,32 +1310,34 @@ class RestRepository extends Query {
|
|
1258
1310
|
const body = {
|
1259
1311
|
filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
|
1260
1312
|
sort: data.sort ? buildSortFilter(data.sort) : void 0,
|
1261
|
-
page: data.
|
1313
|
+
page: data.pagination,
|
1262
1314
|
columns: data.columns
|
1263
1315
|
};
|
1264
|
-
const fetchProps = await __privateGet$
|
1316
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1265
1317
|
const { meta, records: objects } = await queryTable({
|
1266
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$
|
1318
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1267
1319
|
body,
|
1268
1320
|
...fetchProps
|
1269
1321
|
});
|
1270
|
-
const
|
1322
|
+
const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
|
1323
|
+
const records = objects.map((record) => initObject(this.db, schema, __privateGet$4(this, _table), record));
|
1271
1324
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1272
1325
|
return new Page(query, meta, records);
|
1273
1326
|
}
|
1274
1327
|
}
|
1275
1328
|
_table = new WeakMap();
|
1276
|
-
_links = new WeakMap();
|
1277
1329
|
_getFetchProps = new WeakMap();
|
1330
|
+
_cache = new WeakMap();
|
1331
|
+
_schema$1 = new WeakMap();
|
1278
1332
|
_insertRecordWithoutId = new WeakSet();
|
1279
1333
|
insertRecordWithoutId_fn = async function(object) {
|
1280
|
-
const fetchProps = await __privateGet$
|
1334
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1281
1335
|
const record = transformObjectLinks(object);
|
1282
1336
|
const response = await insertRecord({
|
1283
1337
|
pathParams: {
|
1284
1338
|
workspace: "{workspaceId}",
|
1285
1339
|
dbBranchName: "{dbBranch}",
|
1286
|
-
tableName: __privateGet$
|
1340
|
+
tableName: __privateGet$4(this, _table)
|
1287
1341
|
},
|
1288
1342
|
body: record,
|
1289
1343
|
...fetchProps
|
@@ -1296,13 +1350,13 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1296
1350
|
};
|
1297
1351
|
_insertRecordWithId = new WeakSet();
|
1298
1352
|
insertRecordWithId_fn = async function(recordId, object) {
|
1299
|
-
const fetchProps = await __privateGet$
|
1353
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1300
1354
|
const record = transformObjectLinks(object);
|
1301
1355
|
const response = await insertRecordWithID({
|
1302
1356
|
pathParams: {
|
1303
1357
|
workspace: "{workspaceId}",
|
1304
1358
|
dbBranchName: "{dbBranch}",
|
1305
|
-
tableName: __privateGet$
|
1359
|
+
tableName: __privateGet$4(this, _table),
|
1306
1360
|
recordId
|
1307
1361
|
},
|
1308
1362
|
body: record,
|
@@ -1317,10 +1371,10 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1317
1371
|
};
|
1318
1372
|
_bulkInsertTableRecords = new WeakSet();
|
1319
1373
|
bulkInsertTableRecords_fn = async function(objects) {
|
1320
|
-
const fetchProps = await __privateGet$
|
1374
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1321
1375
|
const records = objects.map((object) => transformObjectLinks(object));
|
1322
1376
|
const response = await bulkInsertTableRecords({
|
1323
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$
|
1377
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1324
1378
|
body: { records },
|
1325
1379
|
...fetchProps
|
1326
1380
|
});
|
@@ -1332,10 +1386,10 @@ bulkInsertTableRecords_fn = async function(objects) {
|
|
1332
1386
|
};
|
1333
1387
|
_updateRecordWithID = new WeakSet();
|
1334
1388
|
updateRecordWithID_fn = async function(recordId, object) {
|
1335
|
-
const fetchProps = await __privateGet$
|
1389
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1336
1390
|
const record = transformObjectLinks(object);
|
1337
1391
|
const response = await updateRecordWithID({
|
1338
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$
|
1392
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1339
1393
|
body: record,
|
1340
1394
|
...fetchProps
|
1341
1395
|
});
|
@@ -1346,9 +1400,9 @@ updateRecordWithID_fn = async function(recordId, object) {
|
|
1346
1400
|
};
|
1347
1401
|
_upsertRecordWithID = new WeakSet();
|
1348
1402
|
upsertRecordWithID_fn = async function(recordId, object) {
|
1349
|
-
const fetchProps = await __privateGet$
|
1403
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1350
1404
|
const response = await upsertRecordWithID({
|
1351
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$
|
1405
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1352
1406
|
body: object,
|
1353
1407
|
...fetchProps
|
1354
1408
|
});
|
@@ -1359,47 +1413,63 @@ upsertRecordWithID_fn = async function(recordId, object) {
|
|
1359
1413
|
};
|
1360
1414
|
_deleteRecord = new WeakSet();
|
1361
1415
|
deleteRecord_fn = async function(recordId) {
|
1362
|
-
const fetchProps = await __privateGet$
|
1416
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1363
1417
|
await deleteRecord({
|
1364
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$
|
1418
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1365
1419
|
...fetchProps
|
1366
1420
|
});
|
1367
1421
|
};
|
1368
1422
|
_invalidateCache = new WeakSet();
|
1369
1423
|
invalidateCache_fn = async function(recordId) {
|
1370
|
-
await this.
|
1371
|
-
const cacheItems = await this.
|
1424
|
+
await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1425
|
+
const cacheItems = await __privateGet$4(this, _cache).getAll();
|
1372
1426
|
const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
|
1373
1427
|
for (const [key, value] of queries) {
|
1374
1428
|
const ids = getIds(value);
|
1375
1429
|
if (ids.includes(recordId))
|
1376
|
-
await this.
|
1430
|
+
await __privateGet$4(this, _cache).delete(key);
|
1377
1431
|
}
|
1378
1432
|
};
|
1379
1433
|
_setCacheRecord = new WeakSet();
|
1380
1434
|
setCacheRecord_fn = async function(record) {
|
1381
|
-
|
1435
|
+
if (!__privateGet$4(this, _cache).cacheRecords)
|
1436
|
+
return;
|
1437
|
+
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1382
1438
|
};
|
1383
1439
|
_getCacheRecord = new WeakSet();
|
1384
1440
|
getCacheRecord_fn = async function(recordId) {
|
1385
|
-
|
1441
|
+
if (!__privateGet$4(this, _cache).cacheRecords)
|
1442
|
+
return null;
|
1443
|
+
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1386
1444
|
};
|
1387
1445
|
_setCacheQuery = new WeakSet();
|
1388
1446
|
setCacheQuery_fn = async function(query, meta, records) {
|
1389
|
-
await this.
|
1447
|
+
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
1390
1448
|
};
|
1391
1449
|
_getCacheQuery = new WeakSet();
|
1392
1450
|
getCacheQuery_fn = async function(query) {
|
1393
|
-
const key = `query_${__privateGet$
|
1394
|
-
const result = await this.
|
1451
|
+
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
1452
|
+
const result = await __privateGet$4(this, _cache).get(key);
|
1395
1453
|
if (!result)
|
1396
1454
|
return null;
|
1397
|
-
const { ttl =
|
1455
|
+
const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
|
1398
1456
|
if (!ttl || ttl < 0)
|
1399
1457
|
return result;
|
1400
1458
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
1401
1459
|
return hasExpired ? null : result;
|
1402
1460
|
};
|
1461
|
+
_getSchema$1 = new WeakSet();
|
1462
|
+
getSchema_fn$1 = async function() {
|
1463
|
+
if (__privateGet$4(this, _schema$1))
|
1464
|
+
return __privateGet$4(this, _schema$1);
|
1465
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1466
|
+
const { schema } = await getBranchDetails({
|
1467
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1468
|
+
...fetchProps
|
1469
|
+
});
|
1470
|
+
__privateSet$3(this, _schema$1, schema);
|
1471
|
+
return schema;
|
1472
|
+
};
|
1403
1473
|
const transformObjectLinks = (object) => {
|
1404
1474
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
1405
1475
|
if (key === "xata")
|
@@ -1407,15 +1477,33 @@ const transformObjectLinks = (object) => {
|
|
1407
1477
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1408
1478
|
}, {});
|
1409
1479
|
};
|
1410
|
-
const initObject = (db,
|
1480
|
+
const initObject = (db, schema, table, object) => {
|
1411
1481
|
const result = {};
|
1412
1482
|
Object.assign(result, object);
|
1413
|
-
const
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1483
|
+
const { columns } = schema.tables.find(({ name }) => name === table) ?? {};
|
1484
|
+
if (!columns)
|
1485
|
+
console.error(`Table ${table} not found in schema`);
|
1486
|
+
for (const column of columns ?? []) {
|
1487
|
+
const value = result[column.name];
|
1488
|
+
switch (column.type) {
|
1489
|
+
case "datetime": {
|
1490
|
+
const date = new Date(value);
|
1491
|
+
if (isNaN(date.getTime())) {
|
1492
|
+
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
1493
|
+
} else {
|
1494
|
+
result[column.name] = date;
|
1495
|
+
}
|
1496
|
+
break;
|
1497
|
+
}
|
1498
|
+
case "link": {
|
1499
|
+
const linkTable = column.link?.table;
|
1500
|
+
if (!linkTable) {
|
1501
|
+
console.error(`Failed to parse link for field ${column.name}`);
|
1502
|
+
} else if (value && isObject(value)) {
|
1503
|
+
result[column.name] = initObject(db, schema, linkTable, value);
|
1504
|
+
}
|
1505
|
+
break;
|
1506
|
+
}
|
1419
1507
|
}
|
1420
1508
|
}
|
1421
1509
|
result.read = function() {
|
@@ -1447,7 +1535,7 @@ var __accessCheck$3 = (obj, member, msg) => {
|
|
1447
1535
|
if (!member.has(obj))
|
1448
1536
|
throw TypeError("Cannot " + msg);
|
1449
1537
|
};
|
1450
|
-
var __privateGet$
|
1538
|
+
var __privateGet$3 = (obj, member, getter) => {
|
1451
1539
|
__accessCheck$3(obj, member, "read from private field");
|
1452
1540
|
return getter ? getter.call(obj) : member.get(obj);
|
1453
1541
|
};
|
@@ -1456,31 +1544,39 @@ var __privateAdd$3 = (obj, member, value) => {
|
|
1456
1544
|
throw TypeError("Cannot add the same private member more than once");
|
1457
1545
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1458
1546
|
};
|
1459
|
-
var __privateSet$
|
1547
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
1460
1548
|
__accessCheck$3(obj, member, "write to private field");
|
1461
1549
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1462
1550
|
return value;
|
1463
1551
|
};
|
1464
1552
|
var _map;
|
1465
1553
|
class SimpleCache {
|
1466
|
-
constructor() {
|
1554
|
+
constructor(options = {}) {
|
1467
1555
|
__privateAdd$3(this, _map, void 0);
|
1468
|
-
__privateSet$
|
1556
|
+
__privateSet$2(this, _map, /* @__PURE__ */ new Map());
|
1557
|
+
this.capacity = options.max ?? 500;
|
1558
|
+
this.cacheRecords = options.cacheRecords ?? true;
|
1559
|
+
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1469
1560
|
}
|
1470
1561
|
async getAll() {
|
1471
|
-
return Object.fromEntries(__privateGet$
|
1562
|
+
return Object.fromEntries(__privateGet$3(this, _map));
|
1472
1563
|
}
|
1473
1564
|
async get(key) {
|
1474
|
-
return __privateGet$
|
1565
|
+
return __privateGet$3(this, _map).get(key) ?? null;
|
1475
1566
|
}
|
1476
1567
|
async set(key, value) {
|
1477
|
-
|
1568
|
+
await this.delete(key);
|
1569
|
+
__privateGet$3(this, _map).set(key, value);
|
1570
|
+
if (__privateGet$3(this, _map).size > this.capacity) {
|
1571
|
+
const leastRecentlyUsed = __privateGet$3(this, _map).keys().next().value;
|
1572
|
+
await this.delete(leastRecentlyUsed);
|
1573
|
+
}
|
1478
1574
|
}
|
1479
1575
|
async delete(key) {
|
1480
|
-
__privateGet$
|
1576
|
+
__privateGet$3(this, _map).delete(key);
|
1481
1577
|
}
|
1482
1578
|
async clear() {
|
1483
|
-
return __privateGet$
|
1579
|
+
return __privateGet$3(this, _map).clear();
|
1484
1580
|
}
|
1485
1581
|
}
|
1486
1582
|
_map = new WeakMap();
|
@@ -1508,7 +1604,7 @@ var __accessCheck$2 = (obj, member, msg) => {
|
|
1508
1604
|
if (!member.has(obj))
|
1509
1605
|
throw TypeError("Cannot " + msg);
|
1510
1606
|
};
|
1511
|
-
var __privateGet$
|
1607
|
+
var __privateGet$2 = (obj, member, getter) => {
|
1512
1608
|
__accessCheck$2(obj, member, "read from private field");
|
1513
1609
|
return getter ? getter.call(obj) : member.get(obj);
|
1514
1610
|
};
|
@@ -1519,26 +1615,24 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
1519
1615
|
};
|
1520
1616
|
var _tables;
|
1521
1617
|
class SchemaPlugin extends XataPlugin {
|
1522
|
-
constructor(
|
1618
|
+
constructor(tableNames) {
|
1523
1619
|
super();
|
1524
|
-
this.links = links;
|
1525
1620
|
this.tableNames = tableNames;
|
1526
1621
|
__privateAdd$2(this, _tables, {});
|
1527
1622
|
}
|
1528
1623
|
build(pluginOptions) {
|
1529
|
-
const links = this.links;
|
1530
1624
|
const db = new Proxy({}, {
|
1531
1625
|
get: (_target, table) => {
|
1532
1626
|
if (!isString(table))
|
1533
1627
|
throw new Error("Invalid table name");
|
1534
|
-
if (!__privateGet$
|
1535
|
-
__privateGet$
|
1628
|
+
if (!__privateGet$2(this, _tables)[table]) {
|
1629
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table });
|
1536
1630
|
}
|
1537
|
-
return __privateGet$
|
1631
|
+
return __privateGet$2(this, _tables)[table];
|
1538
1632
|
}
|
1539
1633
|
});
|
1540
1634
|
for (const table of this.tableNames ?? []) {
|
1541
|
-
db[table] = new RestRepository({ db, pluginOptions, table
|
1635
|
+
db[table] = new RestRepository({ db, pluginOptions, table });
|
1542
1636
|
}
|
1543
1637
|
return db;
|
1544
1638
|
}
|
@@ -1549,44 +1643,57 @@ var __accessCheck$1 = (obj, member, msg) => {
|
|
1549
1643
|
if (!member.has(obj))
|
1550
1644
|
throw TypeError("Cannot " + msg);
|
1551
1645
|
};
|
1646
|
+
var __privateGet$1 = (obj, member, getter) => {
|
1647
|
+
__accessCheck$1(obj, member, "read from private field");
|
1648
|
+
return getter ? getter.call(obj) : member.get(obj);
|
1649
|
+
};
|
1552
1650
|
var __privateAdd$1 = (obj, member, value) => {
|
1553
1651
|
if (member.has(obj))
|
1554
1652
|
throw TypeError("Cannot add the same private member more than once");
|
1555
1653
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1556
1654
|
};
|
1655
|
+
var __privateSet$1 = (obj, member, value, setter) => {
|
1656
|
+
__accessCheck$1(obj, member, "write to private field");
|
1657
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
1658
|
+
return value;
|
1659
|
+
};
|
1557
1660
|
var __privateMethod$1 = (obj, member, method) => {
|
1558
1661
|
__accessCheck$1(obj, member, "access private method");
|
1559
1662
|
return method;
|
1560
1663
|
};
|
1561
|
-
var _search, search_fn;
|
1664
|
+
var _schema, _search, search_fn, _getSchema, getSchema_fn;
|
1562
1665
|
class SearchPlugin extends XataPlugin {
|
1563
|
-
constructor(db
|
1666
|
+
constructor(db) {
|
1564
1667
|
super();
|
1565
1668
|
this.db = db;
|
1566
|
-
this.links = links;
|
1567
1669
|
__privateAdd$1(this, _search);
|
1670
|
+
__privateAdd$1(this, _getSchema);
|
1671
|
+
__privateAdd$1(this, _schema, void 0);
|
1568
1672
|
}
|
1569
1673
|
build({ getFetchProps }) {
|
1570
1674
|
return {
|
1571
1675
|
all: async (query, options = {}) => {
|
1572
1676
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1677
|
+
const schema = await __privateMethod$1(this, _getSchema, getSchema_fn).call(this, getFetchProps);
|
1573
1678
|
return records.map((record) => {
|
1574
1679
|
const { table = "orphan" } = record.xata;
|
1575
|
-
return { table, record: initObject(this.db,
|
1680
|
+
return { table, record: initObject(this.db, schema, table, record) };
|
1576
1681
|
});
|
1577
1682
|
},
|
1578
1683
|
byTable: async (query, options = {}) => {
|
1579
1684
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1685
|
+
const schema = await __privateMethod$1(this, _getSchema, getSchema_fn).call(this, getFetchProps);
|
1580
1686
|
return records.reduce((acc, record) => {
|
1581
1687
|
const { table = "orphan" } = record.xata;
|
1582
1688
|
const items = acc[table] ?? [];
|
1583
|
-
const item = initObject(this.db,
|
1689
|
+
const item = initObject(this.db, schema, table, record);
|
1584
1690
|
return { ...acc, [table]: [...items, item] };
|
1585
1691
|
}, {});
|
1586
1692
|
}
|
1587
1693
|
};
|
1588
1694
|
}
|
1589
1695
|
}
|
1696
|
+
_schema = new WeakMap();
|
1590
1697
|
_search = new WeakSet();
|
1591
1698
|
search_fn = async function(query, options, getFetchProps) {
|
1592
1699
|
const fetchProps = await getFetchProps();
|
@@ -1598,6 +1705,18 @@ search_fn = async function(query, options, getFetchProps) {
|
|
1598
1705
|
});
|
1599
1706
|
return records;
|
1600
1707
|
};
|
1708
|
+
_getSchema = new WeakSet();
|
1709
|
+
getSchema_fn = async function(getFetchProps) {
|
1710
|
+
if (__privateGet$1(this, _schema))
|
1711
|
+
return __privateGet$1(this, _schema);
|
1712
|
+
const fetchProps = await getFetchProps();
|
1713
|
+
const { schema } = await getBranchDetails({
|
1714
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1715
|
+
...fetchProps
|
1716
|
+
});
|
1717
|
+
__privateSet$1(this, _schema, schema);
|
1718
|
+
return schema;
|
1719
|
+
};
|
1601
1720
|
|
1602
1721
|
const isBranchStrategyBuilder = (strategy) => {
|
1603
1722
|
return typeof strategy === "function";
|
@@ -1706,7 +1825,7 @@ var __privateMethod = (obj, member, method) => {
|
|
1706
1825
|
const buildClient = (plugins) => {
|
1707
1826
|
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1708
1827
|
return _a = class {
|
1709
|
-
constructor(options = {},
|
1828
|
+
constructor(options = {}, tables) {
|
1710
1829
|
__privateAdd(this, _parseOptions);
|
1711
1830
|
__privateAdd(this, _getFetchProps);
|
1712
1831
|
__privateAdd(this, _evaluateBranch);
|
@@ -1716,8 +1835,8 @@ const buildClient = (plugins) => {
|
|
1716
1835
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1717
1836
|
cache: safeOptions.cache
|
1718
1837
|
};
|
1719
|
-
const db = new SchemaPlugin(
|
1720
|
-
const search = new SearchPlugin(db
|
1838
|
+
const db = new SchemaPlugin(tables).build(pluginOptions);
|
1839
|
+
const search = new SearchPlugin(db).build(pluginOptions);
|
1721
1840
|
this.db = db;
|
1722
1841
|
this.search = search;
|
1723
1842
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
@@ -1737,7 +1856,7 @@ const buildClient = (plugins) => {
|
|
1737
1856
|
const fetch = getFetchImplementation(options?.fetch);
|
1738
1857
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1739
1858
|
const apiKey = options?.apiKey || getAPIKey();
|
1740
|
-
const cache = options?.cache ?? new SimpleCache();
|
1859
|
+
const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
|
1741
1860
|
const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
1742
1861
|
if (!databaseURL || !apiKey) {
|
1743
1862
|
throw new Error("Options databaseURL and apiKey are required");
|
@@ -1808,6 +1927,7 @@ exports.XataApiPlugin = XataApiPlugin;
|
|
1808
1927
|
exports.XataError = XataError;
|
1809
1928
|
exports.XataPlugin = XataPlugin;
|
1810
1929
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
1930
|
+
exports.addGitBranchesEntry = addGitBranchesEntry;
|
1811
1931
|
exports.addTableColumn = addTableColumn;
|
1812
1932
|
exports.buildClient = buildClient;
|
1813
1933
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
@@ -1842,6 +1962,7 @@ exports.getCurrentBranchDetails = getCurrentBranchDetails;
|
|
1842
1962
|
exports.getCurrentBranchName = getCurrentBranchName;
|
1843
1963
|
exports.getDatabaseList = getDatabaseList;
|
1844
1964
|
exports.getDatabaseURL = getDatabaseURL;
|
1965
|
+
exports.getGitBranchesMapping = getGitBranchesMapping;
|
1845
1966
|
exports.getRecord = getRecord;
|
1846
1967
|
exports.getTableColumns = getTableColumns;
|
1847
1968
|
exports.getTableSchema = getTableSchema;
|
@@ -1870,8 +1991,10 @@ exports.notExists = notExists;
|
|
1870
1991
|
exports.operationsByTag = operationsByTag;
|
1871
1992
|
exports.pattern = pattern;
|
1872
1993
|
exports.queryTable = queryTable;
|
1994
|
+
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
1873
1995
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
1874
1996
|
exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
1997
|
+
exports.resolveBranch = resolveBranch;
|
1875
1998
|
exports.searchBranch = searchBranch;
|
1876
1999
|
exports.setTableSchema = setTableSchema;
|
1877
2000
|
exports.startsWith = startsWith;
|