@xata.io/client 0.0.0-alpha.vf45a2df → 0.0.0-alpha.vf4789c2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/index.cjs +177 -100
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +112 -20
- package/dist/index.mjs +159 -101
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# @xata.io/client
|
2
2
|
|
3
|
+
## 0.14.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- [#409](https://github.com/xataio/client-ts/pull/409) [`8812380`](https://github.com/xataio/client-ts/commit/881238062b5eeac2dc8b9ba156720e0acc22c5c5) Thanks [@SferaDev](https://github.com/SferaDev)! - Infer types from schema in codegen
|
8
|
+
|
9
|
+
* [#457](https://github.com/xataio/client-ts/pull/457) [`0584a5b`](https://github.com/xataio/client-ts/commit/0584a5b207a21dbc36ddc1d44b276f1d5bb60dc5) Thanks [@SferaDev](https://github.com/SferaDev)! - Load env variables so that code analysis detects them
|
10
|
+
|
11
|
+
- [#469](https://github.com/xataio/client-ts/pull/469) [`8d8a912`](https://github.com/xataio/client-ts/commit/8d8a9129e36452266c4c12fe35b421f66e572498) Thanks [@gimenete](https://github.com/gimenete)! - Treat branch name specified with third party env variables as git branches in the resolution algorithm
|
12
|
+
|
13
|
+
### Patch Changes
|
14
|
+
|
15
|
+
- [#462](https://github.com/xataio/client-ts/pull/462) [`7547b7e`](https://github.com/xataio/client-ts/commit/7547b7edbc9a95c6620784cc5348316f27502c73) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix bug with RecordArray.map
|
16
|
+
|
17
|
+
* [#472](https://github.com/xataio/client-ts/pull/472) [`e99010c`](https://github.com/xataio/client-ts/commit/e99010c9ab9d355abadcfbcf98b5a3fcc80c307a) Thanks [@SferaDev](https://github.com/SferaDev)! - Add id as entity property
|
18
|
+
|
19
|
+
- [#443](https://github.com/xataio/client-ts/pull/443) [`c4be404`](https://github.com/xataio/client-ts/commit/c4be404a3ecb34df9b1ef4501c92f5bdc221f19c) Thanks [@SferaDev](https://github.com/SferaDev)! - Improve performance with `create([])` operation
|
20
|
+
|
3
21
|
## 0.13.4
|
4
22
|
|
5
23
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
@@ -2,6 +2,24 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
+
function _interopNamespace(e) {
|
6
|
+
if (e && e.__esModule) return e;
|
7
|
+
var n = Object.create(null);
|
8
|
+
if (e) {
|
9
|
+
Object.keys(e).forEach(function (k) {
|
10
|
+
if (k !== 'default') {
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () { return e[k]; }
|
15
|
+
});
|
16
|
+
}
|
17
|
+
});
|
18
|
+
}
|
19
|
+
n["default"] = e;
|
20
|
+
return Object.freeze(n);
|
21
|
+
}
|
22
|
+
|
5
23
|
function notEmpty(value) {
|
6
24
|
return value !== null && value !== void 0;
|
7
25
|
}
|
@@ -26,35 +44,83 @@ function toBase64(value) {
|
|
26
44
|
}
|
27
45
|
}
|
28
46
|
|
29
|
-
function
|
47
|
+
function getEnvironment() {
|
30
48
|
try {
|
31
|
-
if (isObject(process) &&
|
32
|
-
return
|
49
|
+
if (isObject(process) && isObject(process.env)) {
|
50
|
+
return {
|
51
|
+
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
52
|
+
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
53
|
+
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
54
|
+
envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
|
55
|
+
fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
|
56
|
+
};
|
33
57
|
}
|
34
58
|
} catch (err) {
|
35
59
|
}
|
36
60
|
try {
|
37
|
-
if (isObject(Deno) &&
|
38
|
-
return
|
61
|
+
if (isObject(Deno) && isObject(Deno.env)) {
|
62
|
+
return {
|
63
|
+
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
64
|
+
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
65
|
+
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
66
|
+
envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
|
67
|
+
fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
|
68
|
+
};
|
39
69
|
}
|
40
70
|
} catch (err) {
|
41
71
|
}
|
72
|
+
return {
|
73
|
+
apiKey: getGlobalApiKey(),
|
74
|
+
databaseURL: getGlobalDatabaseURL(),
|
75
|
+
branch: getGlobalBranch(),
|
76
|
+
envBranch: void 0,
|
77
|
+
fallbackBranch: getGlobalFallbackBranch()
|
78
|
+
};
|
79
|
+
}
|
80
|
+
function getGlobalApiKey() {
|
81
|
+
try {
|
82
|
+
return XATA_API_KEY;
|
83
|
+
} catch (err) {
|
84
|
+
return void 0;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
function getGlobalDatabaseURL() {
|
88
|
+
try {
|
89
|
+
return XATA_DATABASE_URL;
|
90
|
+
} catch (err) {
|
91
|
+
return void 0;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
function getGlobalBranch() {
|
95
|
+
try {
|
96
|
+
return XATA_BRANCH;
|
97
|
+
} catch (err) {
|
98
|
+
return void 0;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
function getGlobalFallbackBranch() {
|
102
|
+
try {
|
103
|
+
return XATA_FALLBACK_BRANCH;
|
104
|
+
} catch (err) {
|
105
|
+
return void 0;
|
106
|
+
}
|
42
107
|
}
|
43
108
|
async function getGitBranch() {
|
109
|
+
const cmd = ["git", "branch", "--show-current"];
|
110
|
+
const fullCmd = cmd.join(" ");
|
111
|
+
const nodeModule = ["child", "process"].join("_");
|
112
|
+
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
44
113
|
try {
|
45
114
|
if (typeof require === "function") {
|
46
|
-
|
47
|
-
return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
|
115
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
48
116
|
}
|
117
|
+
const { execSync } = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(nodeModule);
|
118
|
+
return execSync(fullCmd, execOptions).toString().trim();
|
49
119
|
} catch (err) {
|
50
120
|
}
|
51
121
|
try {
|
52
122
|
if (isObject(Deno)) {
|
53
|
-
const process2 = Deno.run({
|
54
|
-
cmd: ["git", "branch", "--show-current"],
|
55
|
-
stdout: "piped",
|
56
|
-
stderr: "piped"
|
57
|
-
});
|
123
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
58
124
|
return new TextDecoder().decode(await process2.output()).trim();
|
59
125
|
}
|
60
126
|
} catch (err) {
|
@@ -63,7 +129,8 @@ async function getGitBranch() {
|
|
63
129
|
|
64
130
|
function getAPIKey() {
|
65
131
|
try {
|
66
|
-
|
132
|
+
const { apiKey } = getEnvironment();
|
133
|
+
return apiKey;
|
67
134
|
} catch (err) {
|
68
135
|
return void 0;
|
69
136
|
}
|
@@ -78,7 +145,7 @@ function getFetchImplementation(userFetch) {
|
|
78
145
|
return fetchImpl;
|
79
146
|
}
|
80
147
|
|
81
|
-
const VERSION = "0.0.0-alpha.
|
148
|
+
const VERSION = "0.0.0-alpha.vf4789c2";
|
82
149
|
|
83
150
|
class ErrorWithCause extends Error {
|
84
151
|
constructor(message, options) {
|
@@ -243,6 +310,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
243
310
|
...variables
|
244
311
|
});
|
245
312
|
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
313
|
+
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
246
314
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
247
315
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
248
316
|
method: "delete",
|
@@ -415,6 +483,7 @@ const operationsByTag = {
|
|
415
483
|
updateWorkspaceMemberRole,
|
416
484
|
removeWorkspaceMember,
|
417
485
|
inviteWorkspaceMember,
|
486
|
+
updateWorkspaceMemberInvite,
|
418
487
|
cancelWorkspaceMemberInvite,
|
419
488
|
resendWorkspaceMemberInvite,
|
420
489
|
acceptWorkspaceMemberInvite
|
@@ -504,7 +573,7 @@ var __privateAdd$7 = (obj, member, value) => {
|
|
504
573
|
throw TypeError("Cannot add the same private member more than once");
|
505
574
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
506
575
|
};
|
507
|
-
var __privateSet$
|
576
|
+
var __privateSet$7 = (obj, member, value, setter) => {
|
508
577
|
__accessCheck$7(obj, member, "write to private field");
|
509
578
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
510
579
|
return value;
|
@@ -519,7 +588,7 @@ class XataApiClient {
|
|
519
588
|
if (!apiKey) {
|
520
589
|
throw new Error("Could not resolve a valid apiKey");
|
521
590
|
}
|
522
|
-
__privateSet$
|
591
|
+
__privateSet$7(this, _extraProps, {
|
523
592
|
apiUrl: getHostUrl(provider, "main"),
|
524
593
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
525
594
|
fetchImpl: getFetchImplementation(options.fetch),
|
@@ -646,6 +715,13 @@ class WorkspaceApi {
|
|
646
715
|
...this.extraProps
|
647
716
|
});
|
648
717
|
}
|
718
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
719
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
720
|
+
pathParams: { workspaceId, inviteId },
|
721
|
+
body: { role },
|
722
|
+
...this.extraProps
|
723
|
+
});
|
724
|
+
}
|
649
725
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
650
726
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
651
727
|
pathParams: { workspaceId, inviteId },
|
@@ -956,7 +1032,7 @@ var __privateAdd$6 = (obj, member, value) => {
|
|
956
1032
|
throw TypeError("Cannot add the same private member more than once");
|
957
1033
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
958
1034
|
};
|
959
|
-
var __privateSet$
|
1035
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
960
1036
|
__accessCheck$6(obj, member, "write to private field");
|
961
1037
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
962
1038
|
return value;
|
@@ -965,7 +1041,7 @@ var _query, _page;
|
|
965
1041
|
class Page {
|
966
1042
|
constructor(query, meta, records = []) {
|
967
1043
|
__privateAdd$6(this, _query, void 0);
|
968
|
-
__privateSet$
|
1044
|
+
__privateSet$6(this, _query, query);
|
969
1045
|
this.meta = meta;
|
970
1046
|
this.records = new RecordArray(this, records);
|
971
1047
|
}
|
@@ -994,10 +1070,10 @@ function isCursorPaginationOptions(options) {
|
|
994
1070
|
return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
|
995
1071
|
}
|
996
1072
|
const _RecordArray = class extends Array {
|
997
|
-
constructor(
|
998
|
-
super(..._RecordArray.parseConstructorParams(
|
1073
|
+
constructor(...args) {
|
1074
|
+
super(..._RecordArray.parseConstructorParams(...args));
|
999
1075
|
__privateAdd$6(this, _page, void 0);
|
1000
|
-
__privateSet$
|
1076
|
+
__privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
1001
1077
|
}
|
1002
1078
|
static parseConstructorParams(...args) {
|
1003
1079
|
if (args.length === 1 && typeof args[0] === "number") {
|
@@ -1009,6 +1085,12 @@ const _RecordArray = class extends Array {
|
|
1009
1085
|
}
|
1010
1086
|
return new Array(...args);
|
1011
1087
|
}
|
1088
|
+
toArray() {
|
1089
|
+
return new Array(...this);
|
1090
|
+
}
|
1091
|
+
map(callbackfn, thisArg) {
|
1092
|
+
return this.toArray().map(callbackfn, thisArg);
|
1093
|
+
}
|
1012
1094
|
async nextPage(size, offset) {
|
1013
1095
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1014
1096
|
return new _RecordArray(newPage);
|
@@ -1045,7 +1127,7 @@ var __privateAdd$5 = (obj, member, value) => {
|
|
1045
1127
|
throw TypeError("Cannot add the same private member more than once");
|
1046
1128
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1047
1129
|
};
|
1048
|
-
var __privateSet$
|
1130
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
1049
1131
|
__accessCheck$5(obj, member, "write to private field");
|
1050
1132
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1051
1133
|
return value;
|
@@ -1058,11 +1140,11 @@ const _Query = class {
|
|
1058
1140
|
__privateAdd$5(this, _data, { filter: {} });
|
1059
1141
|
this.meta = { page: { cursor: "start", more: true } };
|
1060
1142
|
this.records = new RecordArray(this, []);
|
1061
|
-
__privateSet$
|
1143
|
+
__privateSet$5(this, _table$1, table);
|
1062
1144
|
if (repository) {
|
1063
|
-
__privateSet$
|
1145
|
+
__privateSet$5(this, _repository, repository);
|
1064
1146
|
} else {
|
1065
|
-
__privateSet$
|
1147
|
+
__privateSet$5(this, _repository, this);
|
1066
1148
|
}
|
1067
1149
|
const parent = cleanParent(data, rawParent);
|
1068
1150
|
__privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
@@ -1239,7 +1321,7 @@ var __privateAdd$4 = (obj, member, value) => {
|
|
1239
1321
|
throw TypeError("Cannot add the same private member more than once");
|
1240
1322
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1241
1323
|
};
|
1242
|
-
var __privateSet$
|
1324
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
1243
1325
|
__accessCheck$4(obj, member, "write to private field");
|
1244
1326
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1245
1327
|
return value;
|
@@ -1248,7 +1330,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1248
1330
|
__accessCheck$4(obj, member, "access private method");
|
1249
1331
|
return method;
|
1250
1332
|
};
|
1251
|
-
var _table, _getFetchProps, _cache,
|
1333
|
+
var _table, _getFetchProps, _cache, _schemaTables$2, _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, _getSchemaTables$1, getSchemaTables_fn$1;
|
1252
1334
|
class Repository extends Query {
|
1253
1335
|
}
|
1254
1336
|
class RestRepository extends Query {
|
@@ -1265,15 +1347,16 @@ class RestRepository extends Query {
|
|
1265
1347
|
__privateAdd$4(this, _getCacheRecord);
|
1266
1348
|
__privateAdd$4(this, _setCacheQuery);
|
1267
1349
|
__privateAdd$4(this, _getCacheQuery);
|
1268
|
-
__privateAdd$4(this,
|
1350
|
+
__privateAdd$4(this, _getSchemaTables$1);
|
1269
1351
|
__privateAdd$4(this, _table, void 0);
|
1270
1352
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1271
1353
|
__privateAdd$4(this, _cache, void 0);
|
1272
|
-
__privateAdd$4(this,
|
1273
|
-
__privateSet$
|
1274
|
-
__privateSet$
|
1354
|
+
__privateAdd$4(this, _schemaTables$2, void 0);
|
1355
|
+
__privateSet$4(this, _table, options.table);
|
1356
|
+
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1275
1357
|
this.db = options.db;
|
1276
|
-
__privateSet$
|
1358
|
+
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1359
|
+
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1277
1360
|
}
|
1278
1361
|
async create(a, b) {
|
1279
1362
|
if (Array.isArray(a)) {
|
@@ -1322,8 +1405,8 @@ class RestRepository extends Query {
|
|
1322
1405
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
|
1323
1406
|
...fetchProps
|
1324
1407
|
});
|
1325
|
-
const
|
1326
|
-
return initObject(this.db,
|
1408
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1409
|
+
return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
|
1327
1410
|
} catch (e) {
|
1328
1411
|
if (isObject(e) && e.status === 404) {
|
1329
1412
|
return null;
|
@@ -1412,8 +1495,8 @@ class RestRepository extends Query {
|
|
1412
1495
|
},
|
1413
1496
|
...fetchProps
|
1414
1497
|
});
|
1415
|
-
const
|
1416
|
-
return records.map((item) => initObject(this.db,
|
1498
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1499
|
+
return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1417
1500
|
}
|
1418
1501
|
async query(query) {
|
1419
1502
|
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
@@ -1432,8 +1515,8 @@ class RestRepository extends Query {
|
|
1432
1515
|
body,
|
1433
1516
|
...fetchProps
|
1434
1517
|
});
|
1435
|
-
const
|
1436
|
-
const records = objects.map((record) => initObject(this.db,
|
1518
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1519
|
+
const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
|
1437
1520
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1438
1521
|
return new Page(query, meta, records);
|
1439
1522
|
}
|
@@ -1441,7 +1524,7 @@ class RestRepository extends Query {
|
|
1441
1524
|
_table = new WeakMap();
|
1442
1525
|
_getFetchProps = new WeakMap();
|
1443
1526
|
_cache = new WeakMap();
|
1444
|
-
|
1527
|
+
_schemaTables$2 = new WeakMap();
|
1445
1528
|
_insertRecordWithoutId = new WeakSet();
|
1446
1529
|
insertRecordWithoutId_fn = async function(object) {
|
1447
1530
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
@@ -1575,17 +1658,17 @@ getCacheQuery_fn = async function(query) {
|
|
1575
1658
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
1576
1659
|
return hasExpired ? null : result;
|
1577
1660
|
};
|
1578
|
-
|
1579
|
-
|
1580
|
-
if (__privateGet$4(this,
|
1581
|
-
return __privateGet$4(this,
|
1661
|
+
_getSchemaTables$1 = new WeakSet();
|
1662
|
+
getSchemaTables_fn$1 = async function() {
|
1663
|
+
if (__privateGet$4(this, _schemaTables$2))
|
1664
|
+
return __privateGet$4(this, _schemaTables$2);
|
1582
1665
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1583
1666
|
const { schema } = await getBranchDetails({
|
1584
1667
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1585
1668
|
...fetchProps
|
1586
1669
|
});
|
1587
|
-
__privateSet$
|
1588
|
-
return schema;
|
1670
|
+
__privateSet$4(this, _schemaTables$2, schema.tables);
|
1671
|
+
return schema.tables;
|
1589
1672
|
};
|
1590
1673
|
const transformObjectLinks = (object) => {
|
1591
1674
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
@@ -1594,11 +1677,11 @@ const transformObjectLinks = (object) => {
|
|
1594
1677
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1595
1678
|
}, {});
|
1596
1679
|
};
|
1597
|
-
const initObject = (db,
|
1680
|
+
const initObject = (db, schemaTables, table, object) => {
|
1598
1681
|
const result = {};
|
1599
1682
|
const { xata, ...rest } = object ?? {};
|
1600
1683
|
Object.assign(result, rest);
|
1601
|
-
const { columns } =
|
1684
|
+
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
1602
1685
|
if (!columns)
|
1603
1686
|
console.error(`Table ${table} not found in schema`);
|
1604
1687
|
for (const column of columns ?? []) {
|
@@ -1618,7 +1701,7 @@ const initObject = (db, schema, table, object) => {
|
|
1618
1701
|
if (!linkTable) {
|
1619
1702
|
console.error(`Failed to parse link for field ${column.name}`);
|
1620
1703
|
} else if (isObject(value)) {
|
1621
|
-
result[column.name] = initObject(db,
|
1704
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value);
|
1622
1705
|
}
|
1623
1706
|
break;
|
1624
1707
|
}
|
@@ -1665,7 +1748,7 @@ var __privateAdd$3 = (obj, member, value) => {
|
|
1665
1748
|
throw TypeError("Cannot add the same private member more than once");
|
1666
1749
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1667
1750
|
};
|
1668
|
-
var __privateSet$
|
1751
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
1669
1752
|
__accessCheck$3(obj, member, "write to private field");
|
1670
1753
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1671
1754
|
return value;
|
@@ -1674,7 +1757,7 @@ var _map;
|
|
1674
1757
|
class SimpleCache {
|
1675
1758
|
constructor(options = {}) {
|
1676
1759
|
__privateAdd$3(this, _map, void 0);
|
1677
|
-
__privateSet$
|
1760
|
+
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1678
1761
|
this.capacity = options.max ?? 500;
|
1679
1762
|
this.cacheRecords = options.cacheRecords ?? true;
|
1680
1763
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
@@ -1734,12 +1817,18 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
1734
1817
|
throw TypeError("Cannot add the same private member more than once");
|
1735
1818
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1736
1819
|
};
|
1737
|
-
var
|
1820
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
1821
|
+
__accessCheck$2(obj, member, "write to private field");
|
1822
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
1823
|
+
return value;
|
1824
|
+
};
|
1825
|
+
var _tables, _schemaTables$1;
|
1738
1826
|
class SchemaPlugin extends XataPlugin {
|
1739
|
-
constructor(
|
1827
|
+
constructor(schemaTables) {
|
1740
1828
|
super();
|
1741
|
-
this.tableNames = tableNames;
|
1742
1829
|
__privateAdd$2(this, _tables, {});
|
1830
|
+
__privateAdd$2(this, _schemaTables$1, void 0);
|
1831
|
+
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1743
1832
|
}
|
1744
1833
|
build(pluginOptions) {
|
1745
1834
|
const db = new Proxy({}, {
|
@@ -1747,18 +1836,20 @@ class SchemaPlugin extends XataPlugin {
|
|
1747
1836
|
if (!isString(table))
|
1748
1837
|
throw new Error("Invalid table name");
|
1749
1838
|
if (__privateGet$2(this, _tables)[table] === void 0) {
|
1750
|
-
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table });
|
1839
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1751
1840
|
}
|
1752
1841
|
return __privateGet$2(this, _tables)[table];
|
1753
1842
|
}
|
1754
1843
|
});
|
1755
|
-
|
1756
|
-
|
1844
|
+
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1845
|
+
for (const table of tableNames) {
|
1846
|
+
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1757
1847
|
}
|
1758
1848
|
return db;
|
1759
1849
|
}
|
1760
1850
|
}
|
1761
1851
|
_tables = new WeakMap();
|
1852
|
+
_schemaTables$1 = new WeakMap();
|
1762
1853
|
|
1763
1854
|
var __accessCheck$1 = (obj, member, msg) => {
|
1764
1855
|
if (!member.has(obj))
|
@@ -1782,39 +1873,40 @@ var __privateMethod$1 = (obj, member, method) => {
|
|
1782
1873
|
__accessCheck$1(obj, member, "access private method");
|
1783
1874
|
return method;
|
1784
1875
|
};
|
1785
|
-
var
|
1876
|
+
var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
|
1786
1877
|
class SearchPlugin extends XataPlugin {
|
1787
|
-
constructor(db) {
|
1878
|
+
constructor(db, schemaTables) {
|
1788
1879
|
super();
|
1789
1880
|
this.db = db;
|
1790
1881
|
__privateAdd$1(this, _search);
|
1791
|
-
__privateAdd$1(this,
|
1792
|
-
__privateAdd$1(this,
|
1882
|
+
__privateAdd$1(this, _getSchemaTables);
|
1883
|
+
__privateAdd$1(this, _schemaTables, void 0);
|
1884
|
+
__privateSet$1(this, _schemaTables, schemaTables);
|
1793
1885
|
}
|
1794
1886
|
build({ getFetchProps }) {
|
1795
1887
|
return {
|
1796
1888
|
all: async (query, options = {}) => {
|
1797
1889
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1798
|
-
const
|
1890
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1799
1891
|
return records.map((record) => {
|
1800
1892
|
const { table = "orphan" } = record.xata;
|
1801
|
-
return { table, record: initObject(this.db,
|
1893
|
+
return { table, record: initObject(this.db, schemaTables, table, record) };
|
1802
1894
|
});
|
1803
1895
|
},
|
1804
1896
|
byTable: async (query, options = {}) => {
|
1805
1897
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1806
|
-
const
|
1898
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1807
1899
|
return records.reduce((acc, record) => {
|
1808
1900
|
const { table = "orphan" } = record.xata;
|
1809
1901
|
const items = acc[table] ?? [];
|
1810
|
-
const item = initObject(this.db,
|
1902
|
+
const item = initObject(this.db, schemaTables, table, record);
|
1811
1903
|
return { ...acc, [table]: [...items, item] };
|
1812
1904
|
}, {});
|
1813
1905
|
}
|
1814
1906
|
};
|
1815
1907
|
}
|
1816
1908
|
}
|
1817
|
-
|
1909
|
+
_schemaTables = new WeakMap();
|
1818
1910
|
_search = new WeakSet();
|
1819
1911
|
search_fn = async function(query, options, getFetchProps) {
|
1820
1912
|
const fetchProps = await getFetchProps();
|
@@ -1826,38 +1918,32 @@ search_fn = async function(query, options, getFetchProps) {
|
|
1826
1918
|
});
|
1827
1919
|
return records;
|
1828
1920
|
};
|
1829
|
-
|
1830
|
-
|
1831
|
-
if (__privateGet$1(this,
|
1832
|
-
return __privateGet$1(this,
|
1921
|
+
_getSchemaTables = new WeakSet();
|
1922
|
+
getSchemaTables_fn = async function(getFetchProps) {
|
1923
|
+
if (__privateGet$1(this, _schemaTables))
|
1924
|
+
return __privateGet$1(this, _schemaTables);
|
1833
1925
|
const fetchProps = await getFetchProps();
|
1834
1926
|
const { schema } = await getBranchDetails({
|
1835
1927
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1836
1928
|
...fetchProps
|
1837
1929
|
});
|
1838
|
-
__privateSet$1(this,
|
1839
|
-
return schema;
|
1930
|
+
__privateSet$1(this, _schemaTables, schema.tables);
|
1931
|
+
return schema.tables;
|
1840
1932
|
};
|
1841
1933
|
|
1842
1934
|
const isBranchStrategyBuilder = (strategy) => {
|
1843
1935
|
return typeof strategy === "function";
|
1844
1936
|
};
|
1845
1937
|
|
1846
|
-
const envBranchNames = [
|
1847
|
-
"XATA_BRANCH",
|
1848
|
-
"VERCEL_GIT_COMMIT_REF",
|
1849
|
-
"CF_PAGES_BRANCH",
|
1850
|
-
"BRANCH"
|
1851
|
-
];
|
1852
1938
|
async function getCurrentBranchName(options) {
|
1853
|
-
const
|
1854
|
-
if (
|
1855
|
-
const details = await getDatabaseBranch(
|
1939
|
+
const { branch, envBranch } = getEnvironment();
|
1940
|
+
if (branch) {
|
1941
|
+
const details = await getDatabaseBranch(branch, options);
|
1856
1942
|
if (details)
|
1857
|
-
return
|
1858
|
-
console.warn(`Branch ${
|
1943
|
+
return branch;
|
1944
|
+
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
1859
1945
|
}
|
1860
|
-
const gitBranch = await getGitBranch();
|
1946
|
+
const gitBranch = envBranch || await getGitBranch();
|
1861
1947
|
return resolveXataBranch(gitBranch, options);
|
1862
1948
|
}
|
1863
1949
|
async function getCurrentBranchDetails(options) {
|
@@ -1873,13 +1959,14 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1873
1959
|
throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
|
1874
1960
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1875
1961
|
const [workspace] = host.split(".");
|
1962
|
+
const { fallbackBranch } = getEnvironment();
|
1876
1963
|
const { branch } = await resolveBranch({
|
1877
1964
|
apiKey,
|
1878
1965
|
apiUrl: databaseURL,
|
1879
1966
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1880
1967
|
workspacesApiUrl: `${protocol}//${host}`,
|
1881
1968
|
pathParams: { dbName, workspace },
|
1882
|
-
queryParams: { gitBranch, fallbackBranch
|
1969
|
+
queryParams: { gitBranch, fallbackBranch }
|
1883
1970
|
});
|
1884
1971
|
return branch;
|
1885
1972
|
}
|
@@ -1907,21 +1994,10 @@ async function getDatabaseBranch(branch, options) {
|
|
1907
1994
|
throw err;
|
1908
1995
|
}
|
1909
1996
|
}
|
1910
|
-
function getBranchByEnvVariable() {
|
1911
|
-
for (const name of envBranchNames) {
|
1912
|
-
const value = getEnvVariable(name);
|
1913
|
-
if (value) {
|
1914
|
-
return value;
|
1915
|
-
}
|
1916
|
-
}
|
1917
|
-
try {
|
1918
|
-
return XATA_BRANCH;
|
1919
|
-
} catch (err) {
|
1920
|
-
}
|
1921
|
-
}
|
1922
1997
|
function getDatabaseURL() {
|
1923
1998
|
try {
|
1924
|
-
|
1999
|
+
const { databaseURL } = getEnvironment();
|
2000
|
+
return databaseURL;
|
1925
2001
|
} catch (err) {
|
1926
2002
|
return void 0;
|
1927
2003
|
}
|
@@ -1952,7 +2028,7 @@ var __privateMethod = (obj, member, method) => {
|
|
1952
2028
|
const buildClient = (plugins) => {
|
1953
2029
|
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1954
2030
|
return _a = class {
|
1955
|
-
constructor(options = {},
|
2031
|
+
constructor(options = {}, schemaTables) {
|
1956
2032
|
__privateAdd(this, _parseOptions);
|
1957
2033
|
__privateAdd(this, _getFetchProps);
|
1958
2034
|
__privateAdd(this, _evaluateBranch);
|
@@ -1962,8 +2038,8 @@ const buildClient = (plugins) => {
|
|
1962
2038
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1963
2039
|
cache: safeOptions.cache
|
1964
2040
|
};
|
1965
|
-
const db = new SchemaPlugin(
|
1966
|
-
const search = new SearchPlugin(db).build(pluginOptions);
|
2041
|
+
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2042
|
+
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
1967
2043
|
this.db = db;
|
1968
2044
|
this.search = search;
|
1969
2045
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
@@ -2134,6 +2210,7 @@ exports.updateRecordWithID = updateRecordWithID;
|
|
2134
2210
|
exports.updateTable = updateTable;
|
2135
2211
|
exports.updateUser = updateUser;
|
2136
2212
|
exports.updateWorkspace = updateWorkspace;
|
2213
|
+
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
2137
2214
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
2138
2215
|
exports.upsertRecordWithID = upsertRecordWithID;
|
2139
2216
|
//# sourceMappingURL=index.cjs.map
|