@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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#485](https://github.com/xataio/client-ts/pull/485) [`a9cbb26`](https://github.com/xataio/client-ts/commit/a9cbb263fbca47cb91a827db252d95a5bb4079a6) Thanks [@SferaDev](https://github.com/SferaDev)! - Allow selecting columns with record operations
8
+
9
+ * [#485](https://github.com/xataio/client-ts/pull/485) [`7e04a3d`](https://github.com/xataio/client-ts/commit/7e04a3d1c51958a44f687a0036ead8bb3f5a2dfb) Thanks [@SferaDev](https://github.com/SferaDev)! - Remove record cache
10
+
11
+ ### Patch Changes
12
+
13
+ - [#503](https://github.com/xataio/client-ts/pull/503) [`6a96ea5`](https://github.com/xataio/client-ts/commit/6a96ea5da4c5b7ca9a99b57ebbce8d6766b5d4d8) Thanks [@xata-bot](https://github.com/xata-bot)! - Update API response types for create of tables and branches
14
+
15
+ * [#421](https://github.com/xataio/client-ts/pull/421) [`43f2560`](https://github.com/xataio/client-ts/commit/43f25605ddd0d2fd514a1542a14389d28955c500) Thanks [@SferaDev](https://github.com/SferaDev)! - Add search boosters and allow prefix search
16
+
3
17
  ## 0.15.0
4
18
 
5
19
  ### Patch Changes
package/Usage.md CHANGED
@@ -155,6 +155,13 @@ const user = await xata.db.users.read(object1);
155
155
  const users = await xata.db.users.read([object1, object2]);
156
156
  ```
157
157
 
158
+ By default an object with the first level properties is returned. If you want to reduce or expand its columns, you can pass an array of columns to the `read()` method.
159
+
160
+ ```ts
161
+ const user = await xata.db.users.read('rec_1234abcdef', ['fullName', 'team.name']);
162
+ const users = await xata.db.users.read(['rec_1234abcdef', 'rec_5678defgh'], ['fullName', 'team.name']);
163
+ ```
164
+
158
165
  ### Creating Records
159
166
 
160
167
  Both the `create()` and `createOrUpdate()` methods can be used to create a new record.
@@ -202,6 +209,19 @@ const users = await xata.db.users.createOrUpdate([
202
209
  ]);
203
210
  ```
204
211
 
212
+ By default, the `create` and `createOrUpdate` methods will return the created record with the first level properties. If you want to reduce or expand its columns, you can pass an array of columns to the `create` or `createOrUpdate` method.
213
+
214
+ ```ts
215
+ const user = await xata.db.users.create('user_admin', { fullName: 'John Smith' }, ['fullName', 'team.name']);
216
+ const users = await xata.db.users.createOrUpdate(
217
+ [
218
+ { id: 'user_admin', fullName: 'John Smith' },
219
+ { id: 'user_manager', fullName: 'Jane Doe' }
220
+ ],
221
+ ['fullName', 'team.name']
222
+ );
223
+ ```
224
+
205
225
  ### Updating records
206
226
 
207
227
  The `update()` method can be used to update an existing record. It will throw an `Error` if the record cannot be found.
@@ -225,6 +245,12 @@ const users = await xata.db.users.update([
225
245
  ]);
226
246
  ```
227
247
 
248
+ By default, the `update` method will return the updated record with the first level properties. If you want to reduce or expand its columns, you can pass an array of columns to the `update` method.
249
+
250
+ ```ts
251
+ const user = await xata.db.users.update('rec_1234abcdef', { fullName: 'John Smith' }, ['fullName', 'team.name']);
252
+ ```
253
+
228
254
  ### Deleting Records
229
255
 
230
256
  The `delete()` method can be used to delete an existing record. It will throw an `Error` if the record cannot be found.
@@ -373,6 +399,13 @@ user?.update({ fullName: 'John Doe' }); // Partially updates the record
373
399
  user?.delete(); // Deletes the record
374
400
  ```
375
401
 
402
+ The `read` and `update` methods return the updated record with the first level properties. If you want to reduce or expand its columns, you can pass an array of columns to the `read` and `update` methods.
403
+
404
+ ```ts
405
+ const user = await xata.db.users.read('rec_1234abcdef');
406
+ user?.read(['fullName', 'team.name']); // Reads the record again with the `fullName` and `team.name` columns
407
+ ```
408
+
376
409
  If the table contains a link property, it will be represented as a `Link` object containing its `id` property and methods to read again or update the linked record.
377
410
 
378
411
  ```ts
package/dist/index.cjs CHANGED
@@ -35,6 +35,9 @@ function isDefined(value) {
35
35
  function isString(value) {
36
36
  return isDefined(value) && typeof value === "string";
37
37
  }
38
+ function isStringArray(value) {
39
+ return isDefined(value) && Array.isArray(value) && value.every(isString);
40
+ }
38
41
  function toBase64(value) {
39
42
  try {
40
43
  return btoa(value);
@@ -145,7 +148,7 @@ function getFetchImplementation(userFetch) {
145
148
  return fetchImpl;
146
149
  }
147
150
 
148
- const VERSION = "0.15.0";
151
+ const VERSION = "0.16.0";
149
152
 
150
153
  class ErrorWithCause extends Error {
151
154
  constructor(message, options) {
@@ -359,11 +362,7 @@ const getBranchDetails = (variables) => fetch$1({
359
362
  method: "get",
360
363
  ...variables
361
364
  });
362
- const createBranch = (variables) => fetch$1({
363
- url: "/db/{dbBranchName}",
364
- method: "put",
365
- ...variables
366
- });
365
+ const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
367
366
  const deleteBranch = (variables) => fetch$1({
368
367
  url: "/db/{dbBranchName}",
369
368
  method: "delete",
@@ -437,11 +436,7 @@ const updateColumn = (variables) => fetch$1({
437
436
  method: "patch",
438
437
  ...variables
439
438
  });
440
- const insertRecord = (variables) => fetch$1({
441
- url: "/db/{dbBranchName}/tables/{tableName}/data",
442
- method: "post",
443
- ...variables
444
- });
439
+ const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
445
440
  const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
446
441
  const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
447
442
  const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
@@ -936,9 +931,10 @@ class RecordsApi {
936
931
  constructor(extraProps) {
937
932
  this.extraProps = extraProps;
938
933
  }
939
- insertRecord(workspace, database, branch, tableName, record) {
934
+ insertRecord(workspace, database, branch, tableName, record, options = {}) {
940
935
  return operationsByTag.records.insertRecord({
941
936
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
937
+ queryParams: options,
942
938
  body: record,
943
939
  ...this.extraProps
944
940
  });
@@ -967,21 +963,24 @@ class RecordsApi {
967
963
  ...this.extraProps
968
964
  });
969
965
  }
970
- deleteRecord(workspace, database, branch, tableName, recordId) {
966
+ deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
971
967
  return operationsByTag.records.deleteRecord({
972
968
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
969
+ queryParams: options,
973
970
  ...this.extraProps
974
971
  });
975
972
  }
976
973
  getRecord(workspace, database, branch, tableName, recordId, options = {}) {
977
974
  return operationsByTag.records.getRecord({
978
975
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
976
+ queryParams: options,
979
977
  ...this.extraProps
980
978
  });
981
979
  }
982
- bulkInsertTableRecords(workspace, database, branch, tableName, records) {
980
+ bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
983
981
  return operationsByTag.records.bulkInsertTableRecords({
984
982
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
983
+ queryParams: options,
985
984
  body: { records },
986
985
  ...this.extraProps
987
986
  });
@@ -1330,7 +1329,7 @@ var __privateMethod$2 = (obj, member, method) => {
1330
1329
  __accessCheck$4(obj, member, "access private method");
1331
1330
  return method;
1332
1331
  };
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;
1332
+ 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;
1334
1333
  class Repository extends Query {
1335
1334
  }
1336
1335
  class RestRepository extends Query {
@@ -1342,9 +1341,6 @@ class RestRepository extends Query {
1342
1341
  __privateAdd$4(this, _updateRecordWithID);
1343
1342
  __privateAdd$4(this, _upsertRecordWithID);
1344
1343
  __privateAdd$4(this, _deleteRecord);
1345
- __privateAdd$4(this, _invalidateCache);
1346
- __privateAdd$4(this, _setCacheRecord);
1347
- __privateAdd$4(this, _getCacheRecord);
1348
1344
  __privateAdd$4(this, _setCacheQuery);
1349
1345
  __privateAdd$4(this, _getCacheQuery);
1350
1346
  __privateAdd$4(this, _getSchemaTables$1);
@@ -1358,51 +1354,51 @@ class RestRepository extends Query {
1358
1354
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1359
1355
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
1360
1356
  }
1361
- async create(a, b) {
1357
+ async create(a, b, c) {
1362
1358
  if (Array.isArray(a)) {
1363
1359
  if (a.length === 0)
1364
1360
  return [];
1365
- const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1366
- await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1367
- return records;
1361
+ const columns = isStringArray(b) ? b : void 0;
1362
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1368
1363
  }
1369
1364
  if (isString(a) && isObject(b)) {
1370
1365
  if (a === "")
1371
1366
  throw new Error("The id can't be empty");
1372
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1373
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1374
- return record;
1367
+ const columns = isStringArray(c) ? c : void 0;
1368
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1375
1369
  }
1376
1370
  if (isObject(a) && isString(a.id)) {
1377
1371
  if (a.id === "")
1378
1372
  throw new Error("The id can't be empty");
1379
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1380
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1381
- return record;
1373
+ const columns = isStringArray(b) ? b : void 0;
1374
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1382
1375
  }
1383
1376
  if (isObject(a)) {
1384
- const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1385
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1386
- return record;
1377
+ const columns = isStringArray(b) ? b : void 0;
1378
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1387
1379
  }
1388
1380
  throw new Error("Invalid arguments for create method");
1389
1381
  }
1390
- async read(a) {
1382
+ async read(a, b) {
1383
+ const columns = isStringArray(b) ? b : ["*"];
1391
1384
  if (Array.isArray(a)) {
1392
1385
  if (a.length === 0)
1393
1386
  return [];
1394
1387
  const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1395
- return this.getAll({ filter: { id: { $any: ids } } });
1388
+ const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
1389
+ const dictionary = finalObjects.reduce((acc, object) => {
1390
+ acc[object.id] = object;
1391
+ return acc;
1392
+ }, {});
1393
+ return ids.map((id2) => dictionary[id2] ?? null);
1396
1394
  }
1397
1395
  const id = isString(a) ? a : a.id;
1398
1396
  if (isString(id)) {
1399
- const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, id);
1400
- if (cacheRecord)
1401
- return cacheRecord;
1402
1397
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1403
1398
  try {
1404
1399
  const response = await getRecord({
1405
1400
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
1401
+ queryParams: { columns },
1406
1402
  ...fetchProps
1407
1403
  });
1408
1404
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
@@ -1414,50 +1410,45 @@ class RestRepository extends Query {
1414
1410
  throw e;
1415
1411
  }
1416
1412
  }
1413
+ return null;
1417
1414
  }
1418
- async update(a, b) {
1415
+ async update(a, b, c) {
1419
1416
  if (Array.isArray(a)) {
1420
1417
  if (a.length === 0)
1421
1418
  return [];
1422
1419
  if (a.length > 100) {
1423
1420
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1424
1421
  }
1425
- return Promise.all(a.map((object) => this.update(object)));
1422
+ const columns = isStringArray(b) ? b : ["*"];
1423
+ return Promise.all(a.map((object) => this.update(object, columns)));
1426
1424
  }
1427
1425
  if (isString(a) && isObject(b)) {
1428
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1429
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1430
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1431
- return record;
1426
+ const columns = isStringArray(c) ? c : void 0;
1427
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1432
1428
  }
1433
1429
  if (isObject(a) && isString(a.id)) {
1434
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1435
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1436
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1437
- return record;
1430
+ const columns = isStringArray(b) ? b : void 0;
1431
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1438
1432
  }
1439
1433
  throw new Error("Invalid arguments for update method");
1440
1434
  }
1441
- async createOrUpdate(a, b) {
1435
+ async createOrUpdate(a, b, c) {
1442
1436
  if (Array.isArray(a)) {
1443
1437
  if (a.length === 0)
1444
1438
  return [];
1445
1439
  if (a.length > 100) {
1446
1440
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1447
1441
  }
1448
- return Promise.all(a.map((object) => this.createOrUpdate(object)));
1442
+ const columns = isStringArray(b) ? b : ["*"];
1443
+ return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1449
1444
  }
1450
1445
  if (isString(a) && isObject(b)) {
1451
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1452
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1453
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1454
- return record;
1446
+ const columns = isStringArray(c) ? c : void 0;
1447
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1455
1448
  }
1456
1449
  if (isObject(a) && isString(a.id)) {
1457
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1458
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1459
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1460
- return record;
1450
+ const columns = isStringArray(c) ? c : void 0;
1451
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1461
1452
  }
1462
1453
  throw new Error("Invalid arguments for createOrUpdate method");
1463
1454
  }
@@ -1473,12 +1464,10 @@ class RestRepository extends Query {
1473
1464
  }
1474
1465
  if (isString(a)) {
1475
1466
  await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1476
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1477
1467
  return;
1478
1468
  }
1479
1469
  if (isObject(a) && isString(a.id)) {
1480
1470
  await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1481
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1482
1471
  return;
1483
1472
  }
1484
1473
  throw new Error("Invalid arguments for delete method");
@@ -1490,8 +1479,10 @@ class RestRepository extends Query {
1490
1479
  body: {
1491
1480
  query,
1492
1481
  fuzziness: options.fuzziness,
1482
+ prefix: options.prefix,
1493
1483
  highlight: options.highlight,
1494
- filter: options.filter
1484
+ filter: options.filter,
1485
+ boosters: options.boosters
1495
1486
  },
1496
1487
  ...fetchProps
1497
1488
  });
@@ -1526,7 +1517,7 @@ _getFetchProps = new WeakMap();
1526
1517
  _cache = new WeakMap();
1527
1518
  _schemaTables$2 = new WeakMap();
1528
1519
  _insertRecordWithoutId = new WeakSet();
1529
- insertRecordWithoutId_fn = async function(object) {
1520
+ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1530
1521
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1531
1522
  const record = transformObjectLinks(object);
1532
1523
  const response = await insertRecord({
@@ -1535,17 +1526,15 @@ insertRecordWithoutId_fn = async function(object) {
1535
1526
  dbBranchName: "{dbBranch}",
1536
1527
  tableName: __privateGet$4(this, _table)
1537
1528
  },
1529
+ queryParams: { columns },
1538
1530
  body: record,
1539
1531
  ...fetchProps
1540
1532
  });
1541
- const finalObject = await this.read(response.id);
1542
- if (!finalObject) {
1543
- throw new Error("The server failed to save the record");
1544
- }
1545
- return finalObject;
1533
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1534
+ return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1546
1535
  };
1547
1536
  _insertRecordWithId = new WeakSet();
1548
- insertRecordWithId_fn = async function(recordId, object) {
1537
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
1549
1538
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1550
1539
  const record = transformObjectLinks(object);
1551
1540
  const response = await insertRecordWithID({
@@ -1556,60 +1545,52 @@ insertRecordWithId_fn = async function(recordId, object) {
1556
1545
  recordId
1557
1546
  },
1558
1547
  body: record,
1559
- queryParams: { createOnly: true },
1548
+ queryParams: { createOnly: true, columns },
1560
1549
  ...fetchProps
1561
1550
  });
1562
- const finalObject = await this.read(response.id);
1563
- if (!finalObject) {
1564
- throw new Error("The server failed to save the record");
1565
- }
1566
- return finalObject;
1551
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1552
+ return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1567
1553
  };
1568
1554
  _bulkInsertTableRecords = new WeakSet();
1569
- bulkInsertTableRecords_fn = async function(objects) {
1555
+ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1570
1556
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1571
1557
  const records = objects.map((object) => transformObjectLinks(object));
1572
- const { recordIDs } = await bulkInsertTableRecords({
1558
+ const response = await bulkInsertTableRecords({
1573
1559
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1560
+ queryParams: { columns },
1574
1561
  body: { records },
1575
1562
  ...fetchProps
1576
1563
  });
1577
- const finalObjects = await this.read(recordIDs);
1578
- if (finalObjects.length !== objects.length) {
1579
- throw new Error("The server failed to save some records");
1564
+ if (!isResponseWithRecords(response)) {
1565
+ throw new Error("Request included columns but server didn't include them");
1580
1566
  }
1581
- const dictionary = finalObjects.reduce((acc, object) => {
1582
- acc[object.id] = object;
1583
- return acc;
1584
- }, {});
1585
- return recordIDs.map((id) => dictionary[id]);
1567
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1568
+ return response.records?.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
1586
1569
  };
1587
1570
  _updateRecordWithID = new WeakSet();
1588
- updateRecordWithID_fn = async function(recordId, object) {
1571
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1589
1572
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1590
1573
  const record = transformObjectLinks(object);
1591
1574
  const response = await updateRecordWithID({
1592
1575
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1576
+ queryParams: { columns },
1593
1577
  body: record,
1594
1578
  ...fetchProps
1595
1579
  });
1596
- const item = await this.read(response.id);
1597
- if (!item)
1598
- throw new Error("The server failed to save the record");
1599
- return item;
1580
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1581
+ return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1600
1582
  };
1601
1583
  _upsertRecordWithID = new WeakSet();
1602
- upsertRecordWithID_fn = async function(recordId, object) {
1584
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1603
1585
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1604
1586
  const response = await upsertRecordWithID({
1605
1587
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1588
+ queryParams: { columns },
1606
1589
  body: object,
1607
1590
  ...fetchProps
1608
1591
  });
1609
- const item = await this.read(response.id);
1610
- if (!item)
1611
- throw new Error("The server failed to save the record");
1612
- return item;
1592
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1593
+ return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1613
1594
  };
1614
1595
  _deleteRecord = new WeakSet();
1615
1596
  deleteRecord_fn = async function(recordId) {
@@ -1619,29 +1600,6 @@ deleteRecord_fn = async function(recordId) {
1619
1600
  ...fetchProps
1620
1601
  });
1621
1602
  };
1622
- _invalidateCache = new WeakSet();
1623
- invalidateCache_fn = async function(recordId) {
1624
- await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1625
- const cacheItems = await __privateGet$4(this, _cache).getAll();
1626
- const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1627
- for (const [key, value] of queries) {
1628
- const ids = getIds(value);
1629
- if (ids.includes(recordId))
1630
- await __privateGet$4(this, _cache).delete(key);
1631
- }
1632
- };
1633
- _setCacheRecord = new WeakSet();
1634
- setCacheRecord_fn = async function(record) {
1635
- if (!__privateGet$4(this, _cache).cacheRecords)
1636
- return;
1637
- await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
1638
- };
1639
- _getCacheRecord = new WeakSet();
1640
- getCacheRecord_fn = async function(recordId) {
1641
- if (!__privateGet$4(this, _cache).cacheRecords)
1642
- return null;
1643
- return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1644
- };
1645
1603
  _setCacheQuery = new WeakSet();
1646
1604
  setCacheQuery_fn = async function(query, meta, records) {
1647
1605
  await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
@@ -1707,11 +1665,11 @@ const initObject = (db, schemaTables, table, object) => {
1707
1665
  }
1708
1666
  }
1709
1667
  }
1710
- result.read = function() {
1711
- return db[table].read(result["id"]);
1668
+ result.read = function(columns2) {
1669
+ return db[table].read(result["id"], columns2);
1712
1670
  };
1713
- result.update = function(data) {
1714
- return db[table].update(result["id"], data);
1671
+ result.update = function(data, columns2) {
1672
+ return db[table].update(result["id"], data, columns2);
1715
1673
  };
1716
1674
  result.delete = function() {
1717
1675
  return db[table].delete(result["id"]);
@@ -1725,14 +1683,8 @@ const initObject = (db, schemaTables, table, object) => {
1725
1683
  Object.freeze(result);
1726
1684
  return result;
1727
1685
  };
1728
- function getIds(value) {
1729
- if (Array.isArray(value)) {
1730
- return value.map((item) => getIds(item)).flat();
1731
- }
1732
- if (!isObject(value))
1733
- return [];
1734
- const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1735
- return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
1686
+ function isResponseWithRecords(value) {
1687
+ return isObject(value) && Array.isArray(value.records);
1736
1688
  }
1737
1689
 
1738
1690
  var __accessCheck$3 = (obj, member, msg) => {
@@ -1759,7 +1711,6 @@ class SimpleCache {
1759
1711
  __privateAdd$3(this, _map, void 0);
1760
1712
  __privateSet$3(this, _map, /* @__PURE__ */ new Map());
1761
1713
  this.capacity = options.max ?? 500;
1762
- this.cacheRecords = options.cacheRecords ?? true;
1763
1714
  this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1764
1715
  }
1765
1716
  async getAll() {
@@ -1910,10 +1861,10 @@ _schemaTables = new WeakMap();
1910
1861
  _search = new WeakSet();
1911
1862
  search_fn = async function(query, options, getFetchProps) {
1912
1863
  const fetchProps = await getFetchProps();
1913
- const { tables, fuzziness, highlight } = options ?? {};
1864
+ const { tables, fuzziness, highlight, prefix } = options ?? {};
1914
1865
  const { records } = await searchBranch({
1915
1866
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1916
- body: { tables, query, fuzziness, highlight },
1867
+ body: { tables, query, fuzziness, prefix, highlight },
1917
1868
  ...fetchProps
1918
1869
  });
1919
1870
  return records;
@@ -2059,7 +2010,7 @@ const buildClient = (plugins) => {
2059
2010
  const fetch = getFetchImplementation(options?.fetch);
2060
2011
  const databaseURL = options?.databaseURL || getDatabaseURL();
2061
2012
  const apiKey = options?.apiKey || getAPIKey();
2062
- const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
2013
+ const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2063
2014
  const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
2064
2015
  if (!databaseURL || !apiKey) {
2065
2016
  throw new Error("Options databaseURL and apiKey are required");