@xata.io/client 0.0.0-alpha.vfbac5b5 → 0.0.0-alpha.vfc692f9
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 +26 -0
- package/Usage.md +33 -0
- package/dist/index.cjs +98 -135
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +397 -121
- package/dist/index.mjs +98 -136
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
@@ -13,6 +13,9 @@ function isDefined(value) {
|
|
13
13
|
function isString(value) {
|
14
14
|
return isDefined(value) && typeof value === "string";
|
15
15
|
}
|
16
|
+
function isStringArray(value) {
|
17
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
18
|
+
}
|
16
19
|
function toBase64(value) {
|
17
20
|
try {
|
18
21
|
return btoa(value);
|
@@ -85,18 +88,20 @@ function getGlobalFallbackBranch() {
|
|
85
88
|
}
|
86
89
|
async function getGitBranch() {
|
87
90
|
const cmd = ["git", "branch", "--show-current"];
|
91
|
+
const fullCmd = cmd.join(" ");
|
88
92
|
const nodeModule = ["child", "process"].join("_");
|
93
|
+
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
89
94
|
try {
|
90
95
|
if (typeof require === "function") {
|
91
|
-
return require(nodeModule).execSync(
|
96
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
92
97
|
}
|
93
98
|
const { execSync } = await import(nodeModule);
|
94
|
-
return execSync(
|
99
|
+
return execSync(fullCmd, execOptions).toString().trim();
|
95
100
|
} catch (err) {
|
96
101
|
}
|
97
102
|
try {
|
98
103
|
if (isObject(Deno)) {
|
99
|
-
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "
|
104
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
100
105
|
return new TextDecoder().decode(await process2.output()).trim();
|
101
106
|
}
|
102
107
|
} catch (err) {
|
@@ -121,7 +126,7 @@ function getFetchImplementation(userFetch) {
|
|
121
126
|
return fetchImpl;
|
122
127
|
}
|
123
128
|
|
124
|
-
const VERSION = "0.0.0-alpha.
|
129
|
+
const VERSION = "0.0.0-alpha.vfc692f9";
|
125
130
|
|
126
131
|
class ErrorWithCause extends Error {
|
127
132
|
constructor(message, options) {
|
@@ -286,6 +291,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
286
291
|
...variables
|
287
292
|
});
|
288
293
|
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
294
|
+
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
289
295
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
290
296
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
291
297
|
method: "delete",
|
@@ -334,11 +340,7 @@ const getBranchDetails = (variables) => fetch$1({
|
|
334
340
|
method: "get",
|
335
341
|
...variables
|
336
342
|
});
|
337
|
-
const createBranch = (variables) => fetch$1({
|
338
|
-
url: "/db/{dbBranchName}",
|
339
|
-
method: "put",
|
340
|
-
...variables
|
341
|
-
});
|
343
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
342
344
|
const deleteBranch = (variables) => fetch$1({
|
343
345
|
url: "/db/{dbBranchName}",
|
344
346
|
method: "delete",
|
@@ -412,11 +414,7 @@ const updateColumn = (variables) => fetch$1({
|
|
412
414
|
method: "patch",
|
413
415
|
...variables
|
414
416
|
});
|
415
|
-
const insertRecord = (variables) => fetch$1({
|
416
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
417
|
-
method: "post",
|
418
|
-
...variables
|
419
|
-
});
|
417
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
420
418
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
421
419
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
422
420
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
@@ -458,6 +456,7 @@ const operationsByTag = {
|
|
458
456
|
updateWorkspaceMemberRole,
|
459
457
|
removeWorkspaceMember,
|
460
458
|
inviteWorkspaceMember,
|
459
|
+
updateWorkspaceMemberInvite,
|
461
460
|
cancelWorkspaceMemberInvite,
|
462
461
|
resendWorkspaceMemberInvite,
|
463
462
|
acceptWorkspaceMemberInvite
|
@@ -689,6 +688,13 @@ class WorkspaceApi {
|
|
689
688
|
...this.extraProps
|
690
689
|
});
|
691
690
|
}
|
691
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
692
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
693
|
+
pathParams: { workspaceId, inviteId },
|
694
|
+
body: { role },
|
695
|
+
...this.extraProps
|
696
|
+
});
|
697
|
+
}
|
692
698
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
693
699
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
694
700
|
pathParams: { workspaceId, inviteId },
|
@@ -903,9 +909,10 @@ class RecordsApi {
|
|
903
909
|
constructor(extraProps) {
|
904
910
|
this.extraProps = extraProps;
|
905
911
|
}
|
906
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
912
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
907
913
|
return operationsByTag.records.insertRecord({
|
908
914
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
915
|
+
queryParams: options,
|
909
916
|
body: record,
|
910
917
|
...this.extraProps
|
911
918
|
});
|
@@ -934,21 +941,24 @@ class RecordsApi {
|
|
934
941
|
...this.extraProps
|
935
942
|
});
|
936
943
|
}
|
937
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
944
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
938
945
|
return operationsByTag.records.deleteRecord({
|
939
946
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
947
|
+
queryParams: options,
|
940
948
|
...this.extraProps
|
941
949
|
});
|
942
950
|
}
|
943
951
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
944
952
|
return operationsByTag.records.getRecord({
|
945
953
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
954
|
+
queryParams: options,
|
946
955
|
...this.extraProps
|
947
956
|
});
|
948
957
|
}
|
949
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
958
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
950
959
|
return operationsByTag.records.bulkInsertTableRecords({
|
951
960
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
961
|
+
queryParams: options,
|
952
962
|
body: { records },
|
953
963
|
...this.extraProps
|
954
964
|
});
|
@@ -1297,7 +1307,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1297
1307
|
__accessCheck$4(obj, member, "access private method");
|
1298
1308
|
return method;
|
1299
1309
|
};
|
1300
|
-
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn,
|
1310
|
+
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
1301
1311
|
class Repository extends Query {
|
1302
1312
|
}
|
1303
1313
|
class RestRepository extends Query {
|
@@ -1309,9 +1319,6 @@ class RestRepository extends Query {
|
|
1309
1319
|
__privateAdd$4(this, _updateRecordWithID);
|
1310
1320
|
__privateAdd$4(this, _upsertRecordWithID);
|
1311
1321
|
__privateAdd$4(this, _deleteRecord);
|
1312
|
-
__privateAdd$4(this, _invalidateCache);
|
1313
|
-
__privateAdd$4(this, _setCacheRecord);
|
1314
|
-
__privateAdd$4(this, _getCacheRecord);
|
1315
1322
|
__privateAdd$4(this, _setCacheQuery);
|
1316
1323
|
__privateAdd$4(this, _getCacheQuery);
|
1317
1324
|
__privateAdd$4(this, _getSchemaTables$1);
|
@@ -1325,51 +1332,51 @@ class RestRepository extends Query {
|
|
1325
1332
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1326
1333
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1327
1334
|
}
|
1328
|
-
async create(a, b) {
|
1335
|
+
async create(a, b, c) {
|
1329
1336
|
if (Array.isArray(a)) {
|
1330
1337
|
if (a.length === 0)
|
1331
1338
|
return [];
|
1332
|
-
const
|
1333
|
-
|
1334
|
-
return records;
|
1339
|
+
const columns = isStringArray(b) ? b : void 0;
|
1340
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1335
1341
|
}
|
1336
1342
|
if (isString(a) && isObject(b)) {
|
1337
1343
|
if (a === "")
|
1338
1344
|
throw new Error("The id can't be empty");
|
1339
|
-
const
|
1340
|
-
|
1341
|
-
return record;
|
1345
|
+
const columns = isStringArray(c) ? c : void 0;
|
1346
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1342
1347
|
}
|
1343
1348
|
if (isObject(a) && isString(a.id)) {
|
1344
1349
|
if (a.id === "")
|
1345
1350
|
throw new Error("The id can't be empty");
|
1346
|
-
const
|
1347
|
-
|
1348
|
-
return record;
|
1351
|
+
const columns = isStringArray(b) ? b : void 0;
|
1352
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1349
1353
|
}
|
1350
1354
|
if (isObject(a)) {
|
1351
|
-
const
|
1352
|
-
|
1353
|
-
return record;
|
1355
|
+
const columns = isStringArray(b) ? b : void 0;
|
1356
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1354
1357
|
}
|
1355
1358
|
throw new Error("Invalid arguments for create method");
|
1356
1359
|
}
|
1357
|
-
async read(a) {
|
1360
|
+
async read(a, b) {
|
1361
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1358
1362
|
if (Array.isArray(a)) {
|
1359
1363
|
if (a.length === 0)
|
1360
1364
|
return [];
|
1361
1365
|
const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
|
1362
|
-
|
1366
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
|
1367
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1368
|
+
acc[object.id] = object;
|
1369
|
+
return acc;
|
1370
|
+
}, {});
|
1371
|
+
return ids.map((id2) => dictionary[id2] ?? null);
|
1363
1372
|
}
|
1364
1373
|
const id = isString(a) ? a : a.id;
|
1365
1374
|
if (isString(id)) {
|
1366
|
-
const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, id);
|
1367
|
-
if (cacheRecord)
|
1368
|
-
return cacheRecord;
|
1369
1375
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1370
1376
|
try {
|
1371
1377
|
const response = await getRecord({
|
1372
1378
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
|
1379
|
+
queryParams: { columns },
|
1373
1380
|
...fetchProps
|
1374
1381
|
});
|
1375
1382
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
@@ -1381,50 +1388,45 @@ class RestRepository extends Query {
|
|
1381
1388
|
throw e;
|
1382
1389
|
}
|
1383
1390
|
}
|
1391
|
+
return null;
|
1384
1392
|
}
|
1385
|
-
async update(a, b) {
|
1393
|
+
async update(a, b, c) {
|
1386
1394
|
if (Array.isArray(a)) {
|
1387
1395
|
if (a.length === 0)
|
1388
1396
|
return [];
|
1389
1397
|
if (a.length > 100) {
|
1390
1398
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1391
1399
|
}
|
1392
|
-
|
1400
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1401
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1393
1402
|
}
|
1394
1403
|
if (isString(a) && isObject(b)) {
|
1395
|
-
|
1396
|
-
|
1397
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1398
|
-
return record;
|
1404
|
+
const columns = isStringArray(c) ? c : void 0;
|
1405
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1399
1406
|
}
|
1400
1407
|
if (isObject(a) && isString(a.id)) {
|
1401
|
-
|
1402
|
-
|
1403
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1404
|
-
return record;
|
1408
|
+
const columns = isStringArray(b) ? b : void 0;
|
1409
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1405
1410
|
}
|
1406
1411
|
throw new Error("Invalid arguments for update method");
|
1407
1412
|
}
|
1408
|
-
async createOrUpdate(a, b) {
|
1413
|
+
async createOrUpdate(a, b, c) {
|
1409
1414
|
if (Array.isArray(a)) {
|
1410
1415
|
if (a.length === 0)
|
1411
1416
|
return [];
|
1412
1417
|
if (a.length > 100) {
|
1413
1418
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1414
1419
|
}
|
1415
|
-
|
1420
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1421
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1416
1422
|
}
|
1417
1423
|
if (isString(a) && isObject(b)) {
|
1418
|
-
|
1419
|
-
|
1420
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1421
|
-
return record;
|
1424
|
+
const columns = isStringArray(c) ? c : void 0;
|
1425
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1422
1426
|
}
|
1423
1427
|
if (isObject(a) && isString(a.id)) {
|
1424
|
-
|
1425
|
-
|
1426
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1427
|
-
return record;
|
1428
|
+
const columns = isStringArray(c) ? c : void 0;
|
1429
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1428
1430
|
}
|
1429
1431
|
throw new Error("Invalid arguments for createOrUpdate method");
|
1430
1432
|
}
|
@@ -1440,12 +1442,10 @@ class RestRepository extends Query {
|
|
1440
1442
|
}
|
1441
1443
|
if (isString(a)) {
|
1442
1444
|
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
|
1443
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1444
1445
|
return;
|
1445
1446
|
}
|
1446
1447
|
if (isObject(a) && isString(a.id)) {
|
1447
1448
|
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
|
1448
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1449
1449
|
return;
|
1450
1450
|
}
|
1451
1451
|
throw new Error("Invalid arguments for delete method");
|
@@ -1457,8 +1457,10 @@ class RestRepository extends Query {
|
|
1457
1457
|
body: {
|
1458
1458
|
query,
|
1459
1459
|
fuzziness: options.fuzziness,
|
1460
|
+
prefix: options.prefix,
|
1460
1461
|
highlight: options.highlight,
|
1461
|
-
filter: options.filter
|
1462
|
+
filter: options.filter,
|
1463
|
+
boosters: options.boosters
|
1462
1464
|
},
|
1463
1465
|
...fetchProps
|
1464
1466
|
});
|
@@ -1493,7 +1495,7 @@ _getFetchProps = new WeakMap();
|
|
1493
1495
|
_cache = new WeakMap();
|
1494
1496
|
_schemaTables$2 = new WeakMap();
|
1495
1497
|
_insertRecordWithoutId = new WeakSet();
|
1496
|
-
insertRecordWithoutId_fn = async function(object) {
|
1498
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1497
1499
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1498
1500
|
const record = transformObjectLinks(object);
|
1499
1501
|
const response = await insertRecord({
|
@@ -1502,17 +1504,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1502
1504
|
dbBranchName: "{dbBranch}",
|
1503
1505
|
tableName: __privateGet$4(this, _table)
|
1504
1506
|
},
|
1507
|
+
queryParams: { columns },
|
1505
1508
|
body: record,
|
1506
1509
|
...fetchProps
|
1507
1510
|
});
|
1508
|
-
const
|
1509
|
-
|
1510
|
-
throw new Error("The server failed to save the record");
|
1511
|
-
}
|
1512
|
-
return finalObject;
|
1511
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1512
|
+
return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
|
1513
1513
|
};
|
1514
1514
|
_insertRecordWithId = new WeakSet();
|
1515
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1515
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1516
1516
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1517
1517
|
const record = transformObjectLinks(object);
|
1518
1518
|
const response = await insertRecordWithID({
|
@@ -1523,60 +1523,52 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1523
1523
|
recordId
|
1524
1524
|
},
|
1525
1525
|
body: record,
|
1526
|
-
queryParams: { createOnly: true },
|
1526
|
+
queryParams: { createOnly: true, columns },
|
1527
1527
|
...fetchProps
|
1528
1528
|
});
|
1529
|
-
const
|
1530
|
-
|
1531
|
-
throw new Error("The server failed to save the record");
|
1532
|
-
}
|
1533
|
-
return finalObject;
|
1529
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1530
|
+
return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
|
1534
1531
|
};
|
1535
1532
|
_bulkInsertTableRecords = new WeakSet();
|
1536
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1533
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
1537
1534
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1538
1535
|
const records = objects.map((object) => transformObjectLinks(object));
|
1539
|
-
const
|
1536
|
+
const response = await bulkInsertTableRecords({
|
1540
1537
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1538
|
+
queryParams: { columns },
|
1541
1539
|
body: { records },
|
1542
1540
|
...fetchProps
|
1543
1541
|
});
|
1544
|
-
|
1545
|
-
|
1546
|
-
throw new Error("The server failed to save some records");
|
1542
|
+
if (!isResponseWithRecords(response)) {
|
1543
|
+
throw new Error("Request included columns but server didn't include them");
|
1547
1544
|
}
|
1548
|
-
const
|
1549
|
-
|
1550
|
-
return acc;
|
1551
|
-
}, {});
|
1552
|
-
return recordIDs.map((id) => dictionary[id]);
|
1545
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1546
|
+
return response.records?.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1553
1547
|
};
|
1554
1548
|
_updateRecordWithID = new WeakSet();
|
1555
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1549
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1556
1550
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1557
1551
|
const record = transformObjectLinks(object);
|
1558
1552
|
const response = await updateRecordWithID({
|
1559
1553
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1554
|
+
queryParams: { columns },
|
1560
1555
|
body: record,
|
1561
1556
|
...fetchProps
|
1562
1557
|
});
|
1563
|
-
const
|
1564
|
-
|
1565
|
-
throw new Error("The server failed to save the record");
|
1566
|
-
return item;
|
1558
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1559
|
+
return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
|
1567
1560
|
};
|
1568
1561
|
_upsertRecordWithID = new WeakSet();
|
1569
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1562
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1570
1563
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1571
1564
|
const response = await upsertRecordWithID({
|
1572
1565
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1566
|
+
queryParams: { columns },
|
1573
1567
|
body: object,
|
1574
1568
|
...fetchProps
|
1575
1569
|
});
|
1576
|
-
const
|
1577
|
-
|
1578
|
-
throw new Error("The server failed to save the record");
|
1579
|
-
return item;
|
1570
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1571
|
+
return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
|
1580
1572
|
};
|
1581
1573
|
_deleteRecord = new WeakSet();
|
1582
1574
|
deleteRecord_fn = async function(recordId) {
|
@@ -1586,29 +1578,6 @@ deleteRecord_fn = async function(recordId) {
|
|
1586
1578
|
...fetchProps
|
1587
1579
|
});
|
1588
1580
|
};
|
1589
|
-
_invalidateCache = new WeakSet();
|
1590
|
-
invalidateCache_fn = async function(recordId) {
|
1591
|
-
await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1592
|
-
const cacheItems = await __privateGet$4(this, _cache).getAll();
|
1593
|
-
const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
|
1594
|
-
for (const [key, value] of queries) {
|
1595
|
-
const ids = getIds(value);
|
1596
|
-
if (ids.includes(recordId))
|
1597
|
-
await __privateGet$4(this, _cache).delete(key);
|
1598
|
-
}
|
1599
|
-
};
|
1600
|
-
_setCacheRecord = new WeakSet();
|
1601
|
-
setCacheRecord_fn = async function(record) {
|
1602
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1603
|
-
return;
|
1604
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1605
|
-
};
|
1606
|
-
_getCacheRecord = new WeakSet();
|
1607
|
-
getCacheRecord_fn = async function(recordId) {
|
1608
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1609
|
-
return null;
|
1610
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1611
|
-
};
|
1612
1581
|
_setCacheQuery = new WeakSet();
|
1613
1582
|
setCacheQuery_fn = async function(query, meta, records) {
|
1614
1583
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
@@ -1674,11 +1643,11 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1674
1643
|
}
|
1675
1644
|
}
|
1676
1645
|
}
|
1677
|
-
result.read = function() {
|
1678
|
-
return db[table].read(result["id"]);
|
1646
|
+
result.read = function(columns2) {
|
1647
|
+
return db[table].read(result["id"], columns2);
|
1679
1648
|
};
|
1680
|
-
result.update = function(data) {
|
1681
|
-
return db[table].update(result["id"], data);
|
1649
|
+
result.update = function(data, columns2) {
|
1650
|
+
return db[table].update(result["id"], data, columns2);
|
1682
1651
|
};
|
1683
1652
|
result.delete = function() {
|
1684
1653
|
return db[table].delete(result["id"]);
|
@@ -1692,14 +1661,8 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1692
1661
|
Object.freeze(result);
|
1693
1662
|
return result;
|
1694
1663
|
};
|
1695
|
-
function
|
1696
|
-
|
1697
|
-
return value.map((item) => getIds(item)).flat();
|
1698
|
-
}
|
1699
|
-
if (!isObject(value))
|
1700
|
-
return [];
|
1701
|
-
const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
|
1702
|
-
return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
|
1664
|
+
function isResponseWithRecords(value) {
|
1665
|
+
return isObject(value) && Array.isArray(value.records);
|
1703
1666
|
}
|
1704
1667
|
|
1705
1668
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1726,7 +1689,6 @@ class SimpleCache {
|
|
1726
1689
|
__privateAdd$3(this, _map, void 0);
|
1727
1690
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1728
1691
|
this.capacity = options.max ?? 500;
|
1729
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1730
1692
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1731
1693
|
}
|
1732
1694
|
async getAll() {
|
@@ -1803,7 +1765,7 @@ class SchemaPlugin extends XataPlugin {
|
|
1803
1765
|
if (!isString(table))
|
1804
1766
|
throw new Error("Invalid table name");
|
1805
1767
|
if (__privateGet$2(this, _tables)[table] === void 0) {
|
1806
|
-
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table });
|
1768
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1807
1769
|
}
|
1808
1770
|
return __privateGet$2(this, _tables)[table];
|
1809
1771
|
}
|
@@ -1877,10 +1839,10 @@ _schemaTables = new WeakMap();
|
|
1877
1839
|
_search = new WeakSet();
|
1878
1840
|
search_fn = async function(query, options, getFetchProps) {
|
1879
1841
|
const fetchProps = await getFetchProps();
|
1880
|
-
const { tables, fuzziness, highlight } = options ?? {};
|
1842
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1881
1843
|
const { records } = await searchBranch({
|
1882
1844
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1883
|
-
body: { tables, query, fuzziness, highlight },
|
1845
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1884
1846
|
...fetchProps
|
1885
1847
|
});
|
1886
1848
|
return records;
|
@@ -2026,7 +1988,7 @@ const buildClient = (plugins) => {
|
|
2026
1988
|
const fetch = getFetchImplementation(options?.fetch);
|
2027
1989
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2028
1990
|
const apiKey = options?.apiKey || getAPIKey();
|
2029
|
-
const cache = options?.cache ?? new SimpleCache({
|
1991
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2030
1992
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
2031
1993
|
if (!databaseURL || !apiKey) {
|
2032
1994
|
throw new Error("Options databaseURL and apiKey are required");
|
@@ -2079,5 +2041,5 @@ class XataError extends Error {
|
|
2079
2041
|
}
|
2080
2042
|
}
|
2081
2043
|
|
2082
|
-
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 };
|
2044
|
+
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, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2083
2045
|
//# sourceMappingURL=index.mjs.map
|