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