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