@xata.io/client 0.15.0 → 0.16.0
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 +14 -0
- package/Usage.md +33 -0
- package/dist/index.cjs +82 -131
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +358 -119
- package/dist/index.mjs +82 -131
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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);
|
@@ -123,7 +126,7 @@ function getFetchImplementation(userFetch) {
|
|
123
126
|
return fetchImpl;
|
124
127
|
}
|
125
128
|
|
126
|
-
const VERSION = "0.
|
129
|
+
const VERSION = "0.16.0";
|
127
130
|
|
128
131
|
class ErrorWithCause extends Error {
|
129
132
|
constructor(message, options) {
|
@@ -337,11 +340,7 @@ const getBranchDetails = (variables) => fetch$1({
|
|
337
340
|
method: "get",
|
338
341
|
...variables
|
339
342
|
});
|
340
|
-
const createBranch = (variables) => fetch$1({
|
341
|
-
url: "/db/{dbBranchName}",
|
342
|
-
method: "put",
|
343
|
-
...variables
|
344
|
-
});
|
343
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
345
344
|
const deleteBranch = (variables) => fetch$1({
|
346
345
|
url: "/db/{dbBranchName}",
|
347
346
|
method: "delete",
|
@@ -415,11 +414,7 @@ const updateColumn = (variables) => fetch$1({
|
|
415
414
|
method: "patch",
|
416
415
|
...variables
|
417
416
|
});
|
418
|
-
const insertRecord = (variables) => fetch$1({
|
419
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
420
|
-
method: "post",
|
421
|
-
...variables
|
422
|
-
});
|
417
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
423
418
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
424
419
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
425
420
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
@@ -914,9 +909,10 @@ class RecordsApi {
|
|
914
909
|
constructor(extraProps) {
|
915
910
|
this.extraProps = extraProps;
|
916
911
|
}
|
917
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
912
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
918
913
|
return operationsByTag.records.insertRecord({
|
919
914
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
915
|
+
queryParams: options,
|
920
916
|
body: record,
|
921
917
|
...this.extraProps
|
922
918
|
});
|
@@ -945,21 +941,24 @@ class RecordsApi {
|
|
945
941
|
...this.extraProps
|
946
942
|
});
|
947
943
|
}
|
948
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
944
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
949
945
|
return operationsByTag.records.deleteRecord({
|
950
946
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
947
|
+
queryParams: options,
|
951
948
|
...this.extraProps
|
952
949
|
});
|
953
950
|
}
|
954
951
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
955
952
|
return operationsByTag.records.getRecord({
|
956
953
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
954
|
+
queryParams: options,
|
957
955
|
...this.extraProps
|
958
956
|
});
|
959
957
|
}
|
960
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
958
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
961
959
|
return operationsByTag.records.bulkInsertTableRecords({
|
962
960
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
961
|
+
queryParams: options,
|
963
962
|
body: { records },
|
964
963
|
...this.extraProps
|
965
964
|
});
|
@@ -1308,7 +1307,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1308
1307
|
__accessCheck$4(obj, member, "access private method");
|
1309
1308
|
return method;
|
1310
1309
|
};
|
1311
|
-
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;
|
1312
1311
|
class Repository extends Query {
|
1313
1312
|
}
|
1314
1313
|
class RestRepository extends Query {
|
@@ -1320,9 +1319,6 @@ class RestRepository extends Query {
|
|
1320
1319
|
__privateAdd$4(this, _updateRecordWithID);
|
1321
1320
|
__privateAdd$4(this, _upsertRecordWithID);
|
1322
1321
|
__privateAdd$4(this, _deleteRecord);
|
1323
|
-
__privateAdd$4(this, _invalidateCache);
|
1324
|
-
__privateAdd$4(this, _setCacheRecord);
|
1325
|
-
__privateAdd$4(this, _getCacheRecord);
|
1326
1322
|
__privateAdd$4(this, _setCacheQuery);
|
1327
1323
|
__privateAdd$4(this, _getCacheQuery);
|
1328
1324
|
__privateAdd$4(this, _getSchemaTables$1);
|
@@ -1336,51 +1332,51 @@ class RestRepository extends Query {
|
|
1336
1332
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1337
1333
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1338
1334
|
}
|
1339
|
-
async create(a, b) {
|
1335
|
+
async create(a, b, c) {
|
1340
1336
|
if (Array.isArray(a)) {
|
1341
1337
|
if (a.length === 0)
|
1342
1338
|
return [];
|
1343
|
-
const
|
1344
|
-
|
1345
|
-
return records;
|
1339
|
+
const columns = isStringArray(b) ? b : void 0;
|
1340
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1346
1341
|
}
|
1347
1342
|
if (isString(a) && isObject(b)) {
|
1348
1343
|
if (a === "")
|
1349
1344
|
throw new Error("The id can't be empty");
|
1350
|
-
const
|
1351
|
-
|
1352
|
-
return record;
|
1345
|
+
const columns = isStringArray(c) ? c : void 0;
|
1346
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1353
1347
|
}
|
1354
1348
|
if (isObject(a) && isString(a.id)) {
|
1355
1349
|
if (a.id === "")
|
1356
1350
|
throw new Error("The id can't be empty");
|
1357
|
-
const
|
1358
|
-
|
1359
|
-
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);
|
1360
1353
|
}
|
1361
1354
|
if (isObject(a)) {
|
1362
|
-
const
|
1363
|
-
|
1364
|
-
return record;
|
1355
|
+
const columns = isStringArray(b) ? b : void 0;
|
1356
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1365
1357
|
}
|
1366
1358
|
throw new Error("Invalid arguments for create method");
|
1367
1359
|
}
|
1368
|
-
async read(a) {
|
1360
|
+
async read(a, b) {
|
1361
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1369
1362
|
if (Array.isArray(a)) {
|
1370
1363
|
if (a.length === 0)
|
1371
1364
|
return [];
|
1372
1365
|
const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
|
1373
|
-
|
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);
|
1374
1372
|
}
|
1375
1373
|
const id = isString(a) ? a : a.id;
|
1376
1374
|
if (isString(id)) {
|
1377
|
-
const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, id);
|
1378
|
-
if (cacheRecord)
|
1379
|
-
return cacheRecord;
|
1380
1375
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1381
1376
|
try {
|
1382
1377
|
const response = await getRecord({
|
1383
1378
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
|
1379
|
+
queryParams: { columns },
|
1384
1380
|
...fetchProps
|
1385
1381
|
});
|
1386
1382
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
@@ -1392,50 +1388,45 @@ class RestRepository extends Query {
|
|
1392
1388
|
throw e;
|
1393
1389
|
}
|
1394
1390
|
}
|
1391
|
+
return null;
|
1395
1392
|
}
|
1396
|
-
async update(a, b) {
|
1393
|
+
async update(a, b, c) {
|
1397
1394
|
if (Array.isArray(a)) {
|
1398
1395
|
if (a.length === 0)
|
1399
1396
|
return [];
|
1400
1397
|
if (a.length > 100) {
|
1401
1398
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1402
1399
|
}
|
1403
|
-
|
1400
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1401
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1404
1402
|
}
|
1405
1403
|
if (isString(a) && isObject(b)) {
|
1406
|
-
|
1407
|
-
|
1408
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1409
|
-
return record;
|
1404
|
+
const columns = isStringArray(c) ? c : void 0;
|
1405
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1410
1406
|
}
|
1411
1407
|
if (isObject(a) && isString(a.id)) {
|
1412
|
-
|
1413
|
-
|
1414
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1415
|
-
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);
|
1416
1410
|
}
|
1417
1411
|
throw new Error("Invalid arguments for update method");
|
1418
1412
|
}
|
1419
|
-
async createOrUpdate(a, b) {
|
1413
|
+
async createOrUpdate(a, b, c) {
|
1420
1414
|
if (Array.isArray(a)) {
|
1421
1415
|
if (a.length === 0)
|
1422
1416
|
return [];
|
1423
1417
|
if (a.length > 100) {
|
1424
1418
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1425
1419
|
}
|
1426
|
-
|
1420
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1421
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1427
1422
|
}
|
1428
1423
|
if (isString(a) && isObject(b)) {
|
1429
|
-
|
1430
|
-
|
1431
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1432
|
-
return record;
|
1424
|
+
const columns = isStringArray(c) ? c : void 0;
|
1425
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1433
1426
|
}
|
1434
1427
|
if (isObject(a) && isString(a.id)) {
|
1435
|
-
|
1436
|
-
|
1437
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1438
|
-
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);
|
1439
1430
|
}
|
1440
1431
|
throw new Error("Invalid arguments for createOrUpdate method");
|
1441
1432
|
}
|
@@ -1451,12 +1442,10 @@ class RestRepository extends Query {
|
|
1451
1442
|
}
|
1452
1443
|
if (isString(a)) {
|
1453
1444
|
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
|
1454
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1455
1445
|
return;
|
1456
1446
|
}
|
1457
1447
|
if (isObject(a) && isString(a.id)) {
|
1458
1448
|
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
|
1459
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1460
1449
|
return;
|
1461
1450
|
}
|
1462
1451
|
throw new Error("Invalid arguments for delete method");
|
@@ -1468,8 +1457,10 @@ class RestRepository extends Query {
|
|
1468
1457
|
body: {
|
1469
1458
|
query,
|
1470
1459
|
fuzziness: options.fuzziness,
|
1460
|
+
prefix: options.prefix,
|
1471
1461
|
highlight: options.highlight,
|
1472
|
-
filter: options.filter
|
1462
|
+
filter: options.filter,
|
1463
|
+
boosters: options.boosters
|
1473
1464
|
},
|
1474
1465
|
...fetchProps
|
1475
1466
|
});
|
@@ -1504,7 +1495,7 @@ _getFetchProps = new WeakMap();
|
|
1504
1495
|
_cache = new WeakMap();
|
1505
1496
|
_schemaTables$2 = new WeakMap();
|
1506
1497
|
_insertRecordWithoutId = new WeakSet();
|
1507
|
-
insertRecordWithoutId_fn = async function(object) {
|
1498
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1508
1499
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1509
1500
|
const record = transformObjectLinks(object);
|
1510
1501
|
const response = await insertRecord({
|
@@ -1513,17 +1504,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1513
1504
|
dbBranchName: "{dbBranch}",
|
1514
1505
|
tableName: __privateGet$4(this, _table)
|
1515
1506
|
},
|
1507
|
+
queryParams: { columns },
|
1516
1508
|
body: record,
|
1517
1509
|
...fetchProps
|
1518
1510
|
});
|
1519
|
-
const
|
1520
|
-
|
1521
|
-
throw new Error("The server failed to save the record");
|
1522
|
-
}
|
1523
|
-
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);
|
1524
1513
|
};
|
1525
1514
|
_insertRecordWithId = new WeakSet();
|
1526
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1515
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1527
1516
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1528
1517
|
const record = transformObjectLinks(object);
|
1529
1518
|
const response = await insertRecordWithID({
|
@@ -1534,60 +1523,52 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1534
1523
|
recordId
|
1535
1524
|
},
|
1536
1525
|
body: record,
|
1537
|
-
queryParams: { createOnly: true },
|
1526
|
+
queryParams: { createOnly: true, columns },
|
1538
1527
|
...fetchProps
|
1539
1528
|
});
|
1540
|
-
const
|
1541
|
-
|
1542
|
-
throw new Error("The server failed to save the record");
|
1543
|
-
}
|
1544
|
-
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);
|
1545
1531
|
};
|
1546
1532
|
_bulkInsertTableRecords = new WeakSet();
|
1547
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1533
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
1548
1534
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1549
1535
|
const records = objects.map((object) => transformObjectLinks(object));
|
1550
|
-
const
|
1536
|
+
const response = await bulkInsertTableRecords({
|
1551
1537
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1538
|
+
queryParams: { columns },
|
1552
1539
|
body: { records },
|
1553
1540
|
...fetchProps
|
1554
1541
|
});
|
1555
|
-
|
1556
|
-
|
1557
|
-
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");
|
1558
1544
|
}
|
1559
|
-
const
|
1560
|
-
|
1561
|
-
return acc;
|
1562
|
-
}, {});
|
1563
|
-
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));
|
1564
1547
|
};
|
1565
1548
|
_updateRecordWithID = new WeakSet();
|
1566
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1549
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1567
1550
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1568
1551
|
const record = transformObjectLinks(object);
|
1569
1552
|
const response = await updateRecordWithID({
|
1570
1553
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1554
|
+
queryParams: { columns },
|
1571
1555
|
body: record,
|
1572
1556
|
...fetchProps
|
1573
1557
|
});
|
1574
|
-
const
|
1575
|
-
|
1576
|
-
throw new Error("The server failed to save the record");
|
1577
|
-
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);
|
1578
1560
|
};
|
1579
1561
|
_upsertRecordWithID = new WeakSet();
|
1580
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1562
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1581
1563
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1582
1564
|
const response = await upsertRecordWithID({
|
1583
1565
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1566
|
+
queryParams: { columns },
|
1584
1567
|
body: object,
|
1585
1568
|
...fetchProps
|
1586
1569
|
});
|
1587
|
-
const
|
1588
|
-
|
1589
|
-
throw new Error("The server failed to save the record");
|
1590
|
-
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);
|
1591
1572
|
};
|
1592
1573
|
_deleteRecord = new WeakSet();
|
1593
1574
|
deleteRecord_fn = async function(recordId) {
|
@@ -1597,29 +1578,6 @@ deleteRecord_fn = async function(recordId) {
|
|
1597
1578
|
...fetchProps
|
1598
1579
|
});
|
1599
1580
|
};
|
1600
|
-
_invalidateCache = new WeakSet();
|
1601
|
-
invalidateCache_fn = async function(recordId) {
|
1602
|
-
await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1603
|
-
const cacheItems = await __privateGet$4(this, _cache).getAll();
|
1604
|
-
const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
|
1605
|
-
for (const [key, value] of queries) {
|
1606
|
-
const ids = getIds(value);
|
1607
|
-
if (ids.includes(recordId))
|
1608
|
-
await __privateGet$4(this, _cache).delete(key);
|
1609
|
-
}
|
1610
|
-
};
|
1611
|
-
_setCacheRecord = new WeakSet();
|
1612
|
-
setCacheRecord_fn = async function(record) {
|
1613
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1614
|
-
return;
|
1615
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1616
|
-
};
|
1617
|
-
_getCacheRecord = new WeakSet();
|
1618
|
-
getCacheRecord_fn = async function(recordId) {
|
1619
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1620
|
-
return null;
|
1621
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1622
|
-
};
|
1623
1581
|
_setCacheQuery = new WeakSet();
|
1624
1582
|
setCacheQuery_fn = async function(query, meta, records) {
|
1625
1583
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
@@ -1685,11 +1643,11 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1685
1643
|
}
|
1686
1644
|
}
|
1687
1645
|
}
|
1688
|
-
result.read = function() {
|
1689
|
-
return db[table].read(result["id"]);
|
1646
|
+
result.read = function(columns2) {
|
1647
|
+
return db[table].read(result["id"], columns2);
|
1690
1648
|
};
|
1691
|
-
result.update = function(data) {
|
1692
|
-
return db[table].update(result["id"], data);
|
1649
|
+
result.update = function(data, columns2) {
|
1650
|
+
return db[table].update(result["id"], data, columns2);
|
1693
1651
|
};
|
1694
1652
|
result.delete = function() {
|
1695
1653
|
return db[table].delete(result["id"]);
|
@@ -1703,14 +1661,8 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1703
1661
|
Object.freeze(result);
|
1704
1662
|
return result;
|
1705
1663
|
};
|
1706
|
-
function
|
1707
|
-
|
1708
|
-
return value.map((item) => getIds(item)).flat();
|
1709
|
-
}
|
1710
|
-
if (!isObject(value))
|
1711
|
-
return [];
|
1712
|
-
const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
|
1713
|
-
return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
|
1664
|
+
function isResponseWithRecords(value) {
|
1665
|
+
return isObject(value) && Array.isArray(value.records);
|
1714
1666
|
}
|
1715
1667
|
|
1716
1668
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1737,7 +1689,6 @@ class SimpleCache {
|
|
1737
1689
|
__privateAdd$3(this, _map, void 0);
|
1738
1690
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1739
1691
|
this.capacity = options.max ?? 500;
|
1740
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1741
1692
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1742
1693
|
}
|
1743
1694
|
async getAll() {
|
@@ -1888,10 +1839,10 @@ _schemaTables = new WeakMap();
|
|
1888
1839
|
_search = new WeakSet();
|
1889
1840
|
search_fn = async function(query, options, getFetchProps) {
|
1890
1841
|
const fetchProps = await getFetchProps();
|
1891
|
-
const { tables, fuzziness, highlight } = options ?? {};
|
1842
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1892
1843
|
const { records } = await searchBranch({
|
1893
1844
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1894
|
-
body: { tables, query, fuzziness, highlight },
|
1845
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1895
1846
|
...fetchProps
|
1896
1847
|
});
|
1897
1848
|
return records;
|
@@ -2037,7 +1988,7 @@ const buildClient = (plugins) => {
|
|
2037
1988
|
const fetch = getFetchImplementation(options?.fetch);
|
2038
1989
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2039
1990
|
const apiKey = options?.apiKey || getAPIKey();
|
2040
|
-
const cache = options?.cache ?? new SimpleCache({
|
1991
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2041
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 });
|
2042
1993
|
if (!databaseURL || !apiKey) {
|
2043
1994
|
throw new Error("Options databaseURL and apiKey are required");
|