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