@xata.io/client 0.0.0-alpha.vdfb8abc → 0.0.0-alpha.ve014f78

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/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);
@@ -107,18 +110,20 @@ function getGlobalFallbackBranch() {
107
110
  }
108
111
  async function getGitBranch() {
109
112
  const cmd = ["git", "branch", "--show-current"];
113
+ const fullCmd = cmd.join(" ");
110
114
  const nodeModule = ["child", "process"].join("_");
115
+ const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
111
116
  try {
112
117
  if (typeof require === "function") {
113
- return require(nodeModule).execSync(cmd.join(" "), { encoding: "utf-8" }).trim();
118
+ return require(nodeModule).execSync(fullCmd, execOptions).trim();
114
119
  }
115
120
  const { execSync } = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(nodeModule);
116
- return execSync(cmd.join(" "), { encoding: "utf-8" }).toString().trim();
121
+ return execSync(fullCmd, execOptions).toString().trim();
117
122
  } catch (err) {
118
123
  }
119
124
  try {
120
125
  if (isObject(Deno)) {
121
- const process2 = Deno.run({ cmd, stdout: "piped", stderr: "piped" });
126
+ const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
122
127
  return new TextDecoder().decode(await process2.output()).trim();
123
128
  }
124
129
  } catch (err) {
@@ -138,12 +143,14 @@ function getFetchImplementation(userFetch) {
138
143
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
139
144
  const fetchImpl = userFetch ?? globalFetch;
140
145
  if (!fetchImpl) {
141
- throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
146
+ throw new Error(
147
+ `The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`
148
+ );
142
149
  }
143
150
  return fetchImpl;
144
151
  }
145
152
 
146
- const VERSION = "0.0.0-alpha.vdfb8abc";
153
+ const VERSION = "0.0.0-alpha.ve014f78";
147
154
 
148
155
  class ErrorWithCause extends Error {
149
156
  constructor(message, options) {
@@ -357,11 +364,7 @@ const getBranchDetails = (variables) => fetch$1({
357
364
  method: "get",
358
365
  ...variables
359
366
  });
360
- const createBranch = (variables) => fetch$1({
361
- url: "/db/{dbBranchName}",
362
- method: "put",
363
- ...variables
364
- });
367
+ const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
365
368
  const deleteBranch = (variables) => fetch$1({
366
369
  url: "/db/{dbBranchName}",
367
370
  method: "delete",
@@ -435,11 +438,7 @@ const updateColumn = (variables) => fetch$1({
435
438
  method: "patch",
436
439
  ...variables
437
440
  });
438
- const insertRecord = (variables) => fetch$1({
439
- url: "/db/{dbBranchName}/tables/{tableName}/data",
440
- method: "post",
441
- ...variables
442
- });
441
+ const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
443
442
  const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
444
443
  const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
445
444
  const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
@@ -934,9 +933,10 @@ class RecordsApi {
934
933
  constructor(extraProps) {
935
934
  this.extraProps = extraProps;
936
935
  }
937
- insertRecord(workspace, database, branch, tableName, record) {
936
+ insertRecord(workspace, database, branch, tableName, record, options = {}) {
938
937
  return operationsByTag.records.insertRecord({
939
938
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
939
+ queryParams: options,
940
940
  body: record,
941
941
  ...this.extraProps
942
942
  });
@@ -965,21 +965,24 @@ class RecordsApi {
965
965
  ...this.extraProps
966
966
  });
967
967
  }
968
- deleteRecord(workspace, database, branch, tableName, recordId) {
968
+ deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
969
969
  return operationsByTag.records.deleteRecord({
970
970
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
971
+ queryParams: options,
971
972
  ...this.extraProps
972
973
  });
973
974
  }
974
975
  getRecord(workspace, database, branch, tableName, recordId, options = {}) {
975
976
  return operationsByTag.records.getRecord({
976
977
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
978
+ queryParams: options,
977
979
  ...this.extraProps
978
980
  });
979
981
  }
980
- bulkInsertTableRecords(workspace, database, branch, tableName, records) {
982
+ bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
981
983
  return operationsByTag.records.bulkInsertTableRecords({
982
984
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
985
+ queryParams: options,
983
986
  body: { records },
984
987
  ...this.extraProps
985
988
  });
@@ -1203,7 +1206,12 @@ const _Query = class {
1203
1206
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
1204
1207
  }
1205
1208
  select(columns) {
1206
- return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { columns }, __privateGet$5(this, _data));
1209
+ return new _Query(
1210
+ __privateGet$5(this, _repository),
1211
+ __privateGet$5(this, _table$1),
1212
+ { columns },
1213
+ __privateGet$5(this, _data)
1214
+ );
1207
1215
  }
1208
1216
  getPaginated(options = {}) {
1209
1217
  const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
@@ -1328,7 +1336,7 @@ var __privateMethod$2 = (obj, member, method) => {
1328
1336
  __accessCheck$4(obj, member, "access private method");
1329
1337
  return method;
1330
1338
  };
1331
- 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;
1339
+ 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;
1332
1340
  class Repository extends Query {
1333
1341
  }
1334
1342
  class RestRepository extends Query {
@@ -1340,9 +1348,6 @@ class RestRepository extends Query {
1340
1348
  __privateAdd$4(this, _updateRecordWithID);
1341
1349
  __privateAdd$4(this, _upsertRecordWithID);
1342
1350
  __privateAdd$4(this, _deleteRecord);
1343
- __privateAdd$4(this, _invalidateCache);
1344
- __privateAdd$4(this, _setCacheRecord);
1345
- __privateAdd$4(this, _getCacheRecord);
1346
1351
  __privateAdd$4(this, _setCacheQuery);
1347
1352
  __privateAdd$4(this, _getCacheQuery);
1348
1353
  __privateAdd$4(this, _getSchemaTables$1);
@@ -1356,51 +1361,51 @@ class RestRepository extends Query {
1356
1361
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1357
1362
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
1358
1363
  }
1359
- async create(a, b) {
1364
+ async create(a, b, c) {
1360
1365
  if (Array.isArray(a)) {
1361
1366
  if (a.length === 0)
1362
1367
  return [];
1363
- const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1364
- await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1365
- return records;
1368
+ const columns = isStringArray(b) ? b : void 0;
1369
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1366
1370
  }
1367
1371
  if (isString(a) && isObject(b)) {
1368
1372
  if (a === "")
1369
1373
  throw new Error("The id can't be empty");
1370
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1371
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1372
- return record;
1374
+ const columns = isStringArray(c) ? c : void 0;
1375
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1373
1376
  }
1374
1377
  if (isObject(a) && isString(a.id)) {
1375
1378
  if (a.id === "")
1376
1379
  throw new Error("The id can't be empty");
1377
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1378
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1379
- return record;
1380
+ const columns = isStringArray(b) ? b : void 0;
1381
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1380
1382
  }
1381
1383
  if (isObject(a)) {
1382
- const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1383
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1384
- return record;
1384
+ const columns = isStringArray(b) ? b : void 0;
1385
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1385
1386
  }
1386
1387
  throw new Error("Invalid arguments for create method");
1387
1388
  }
1388
- async read(a) {
1389
+ async read(a, b) {
1390
+ const columns = isStringArray(b) ? b : ["*"];
1389
1391
  if (Array.isArray(a)) {
1390
1392
  if (a.length === 0)
1391
1393
  return [];
1392
1394
  const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1393
- return this.getAll({ filter: { id: { $any: ids } } });
1395
+ const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
1396
+ const dictionary = finalObjects.reduce((acc, object) => {
1397
+ acc[object.id] = object;
1398
+ return acc;
1399
+ }, {});
1400
+ return ids.map((id2) => dictionary[id2] ?? null);
1394
1401
  }
1395
1402
  const id = isString(a) ? a : a.id;
1396
1403
  if (isString(id)) {
1397
- const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, id);
1398
- if (cacheRecord)
1399
- return cacheRecord;
1400
1404
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1401
1405
  try {
1402
1406
  const response = await getRecord({
1403
1407
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
1408
+ queryParams: { columns },
1404
1409
  ...fetchProps
1405
1410
  });
1406
1411
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
@@ -1412,50 +1417,45 @@ class RestRepository extends Query {
1412
1417
  throw e;
1413
1418
  }
1414
1419
  }
1420
+ return null;
1415
1421
  }
1416
- async update(a, b) {
1422
+ async update(a, b, c) {
1417
1423
  if (Array.isArray(a)) {
1418
1424
  if (a.length === 0)
1419
1425
  return [];
1420
1426
  if (a.length > 100) {
1421
1427
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1422
1428
  }
1423
- return Promise.all(a.map((object) => this.update(object)));
1429
+ const columns = isStringArray(b) ? b : ["*"];
1430
+ return Promise.all(a.map((object) => this.update(object, columns)));
1424
1431
  }
1425
1432
  if (isString(a) && isObject(b)) {
1426
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1427
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1428
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1429
- return record;
1433
+ const columns = isStringArray(c) ? c : void 0;
1434
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1430
1435
  }
1431
1436
  if (isObject(a) && isString(a.id)) {
1432
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1433
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1434
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1435
- return record;
1437
+ const columns = isStringArray(b) ? b : void 0;
1438
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1436
1439
  }
1437
1440
  throw new Error("Invalid arguments for update method");
1438
1441
  }
1439
- async createOrUpdate(a, b) {
1442
+ async createOrUpdate(a, b, c) {
1440
1443
  if (Array.isArray(a)) {
1441
1444
  if (a.length === 0)
1442
1445
  return [];
1443
1446
  if (a.length > 100) {
1444
1447
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1445
1448
  }
1446
- return Promise.all(a.map((object) => this.createOrUpdate(object)));
1449
+ const columns = isStringArray(b) ? b : ["*"];
1450
+ return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1447
1451
  }
1448
1452
  if (isString(a) && isObject(b)) {
1449
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1450
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1451
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1452
- return record;
1453
+ const columns = isStringArray(c) ? c : void 0;
1454
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1453
1455
  }
1454
1456
  if (isObject(a) && isString(a.id)) {
1455
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1456
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1457
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1458
- return record;
1457
+ const columns = isStringArray(c) ? c : void 0;
1458
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1459
1459
  }
1460
1460
  throw new Error("Invalid arguments for createOrUpdate method");
1461
1461
  }
@@ -1471,12 +1471,10 @@ class RestRepository extends Query {
1471
1471
  }
1472
1472
  if (isString(a)) {
1473
1473
  await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1474
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1475
1474
  return;
1476
1475
  }
1477
1476
  if (isObject(a) && isString(a.id)) {
1478
1477
  await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1479
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1480
1478
  return;
1481
1479
  }
1482
1480
  throw new Error("Invalid arguments for delete method");
@@ -1488,8 +1486,10 @@ class RestRepository extends Query {
1488
1486
  body: {
1489
1487
  query,
1490
1488
  fuzziness: options.fuzziness,
1489
+ prefix: options.prefix,
1491
1490
  highlight: options.highlight,
1492
- filter: options.filter
1491
+ filter: options.filter,
1492
+ boosters: options.boosters
1493
1493
  },
1494
1494
  ...fetchProps
1495
1495
  });
@@ -1524,7 +1524,7 @@ _getFetchProps = new WeakMap();
1524
1524
  _cache = new WeakMap();
1525
1525
  _schemaTables$2 = new WeakMap();
1526
1526
  _insertRecordWithoutId = new WeakSet();
1527
- insertRecordWithoutId_fn = async function(object) {
1527
+ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1528
1528
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1529
1529
  const record = transformObjectLinks(object);
1530
1530
  const response = await insertRecord({
@@ -1533,17 +1533,15 @@ insertRecordWithoutId_fn = async function(object) {
1533
1533
  dbBranchName: "{dbBranch}",
1534
1534
  tableName: __privateGet$4(this, _table)
1535
1535
  },
1536
+ queryParams: { columns },
1536
1537
  body: record,
1537
1538
  ...fetchProps
1538
1539
  });
1539
- const finalObject = await this.read(response.id);
1540
- if (!finalObject) {
1541
- throw new Error("The server failed to save the record");
1542
- }
1543
- return finalObject;
1540
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1541
+ return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1544
1542
  };
1545
1543
  _insertRecordWithId = new WeakSet();
1546
- insertRecordWithId_fn = async function(recordId, object) {
1544
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
1547
1545
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1548
1546
  const record = transformObjectLinks(object);
1549
1547
  const response = await insertRecordWithID({
@@ -1554,60 +1552,52 @@ insertRecordWithId_fn = async function(recordId, object) {
1554
1552
  recordId
1555
1553
  },
1556
1554
  body: record,
1557
- queryParams: { createOnly: true },
1555
+ queryParams: { createOnly: true, columns },
1558
1556
  ...fetchProps
1559
1557
  });
1560
- const finalObject = await this.read(response.id);
1561
- if (!finalObject) {
1562
- throw new Error("The server failed to save the record");
1563
- }
1564
- return finalObject;
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);
1565
1560
  };
1566
1561
  _bulkInsertTableRecords = new WeakSet();
1567
- bulkInsertTableRecords_fn = async function(objects) {
1562
+ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1568
1563
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1569
1564
  const records = objects.map((object) => transformObjectLinks(object));
1570
- const { recordIDs } = await bulkInsertTableRecords({
1565
+ const response = await bulkInsertTableRecords({
1571
1566
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1567
+ queryParams: { columns },
1572
1568
  body: { records },
1573
1569
  ...fetchProps
1574
1570
  });
1575
- const finalObjects = await this.read(recordIDs);
1576
- if (finalObjects.length !== objects.length) {
1577
- throw new Error("The server failed to save some records");
1571
+ if (!isResponseWithRecords(response)) {
1572
+ throw new Error("Request included columns but server didn't include them");
1578
1573
  }
1579
- const dictionary = finalObjects.reduce((acc, object) => {
1580
- acc[object.id] = object;
1581
- return acc;
1582
- }, {});
1583
- return recordIDs.map((id) => dictionary[id]);
1574
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1575
+ return response.records?.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
1584
1576
  };
1585
1577
  _updateRecordWithID = new WeakSet();
1586
- updateRecordWithID_fn = async function(recordId, object) {
1578
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1587
1579
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1588
1580
  const record = transformObjectLinks(object);
1589
1581
  const response = await updateRecordWithID({
1590
1582
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1583
+ queryParams: { columns },
1591
1584
  body: record,
1592
1585
  ...fetchProps
1593
1586
  });
1594
- const item = await this.read(response.id);
1595
- if (!item)
1596
- throw new Error("The server failed to save the record");
1597
- return item;
1587
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1588
+ return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1598
1589
  };
1599
1590
  _upsertRecordWithID = new WeakSet();
1600
- upsertRecordWithID_fn = async function(recordId, object) {
1591
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1601
1592
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1602
1593
  const response = await upsertRecordWithID({
1603
1594
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1595
+ queryParams: { columns },
1604
1596
  body: object,
1605
1597
  ...fetchProps
1606
1598
  });
1607
- const item = await this.read(response.id);
1608
- if (!item)
1609
- throw new Error("The server failed to save the record");
1610
- return item;
1599
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1600
+ return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1611
1601
  };
1612
1602
  _deleteRecord = new WeakSet();
1613
1603
  deleteRecord_fn = async function(recordId) {
@@ -1617,29 +1607,6 @@ deleteRecord_fn = async function(recordId) {
1617
1607
  ...fetchProps
1618
1608
  });
1619
1609
  };
1620
- _invalidateCache = new WeakSet();
1621
- invalidateCache_fn = async function(recordId) {
1622
- await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1623
- const cacheItems = await __privateGet$4(this, _cache).getAll();
1624
- const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1625
- for (const [key, value] of queries) {
1626
- const ids = getIds(value);
1627
- if (ids.includes(recordId))
1628
- await __privateGet$4(this, _cache).delete(key);
1629
- }
1630
- };
1631
- _setCacheRecord = new WeakSet();
1632
- setCacheRecord_fn = async function(record) {
1633
- if (!__privateGet$4(this, _cache).cacheRecords)
1634
- return;
1635
- await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
1636
- };
1637
- _getCacheRecord = new WeakSet();
1638
- getCacheRecord_fn = async function(recordId) {
1639
- if (!__privateGet$4(this, _cache).cacheRecords)
1640
- return null;
1641
- return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1642
- };
1643
1610
  _setCacheQuery = new WeakSet();
1644
1611
  setCacheQuery_fn = async function(query, meta, records) {
1645
1612
  await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
@@ -1705,11 +1672,11 @@ const initObject = (db, schemaTables, table, object) => {
1705
1672
  }
1706
1673
  }
1707
1674
  }
1708
- result.read = function() {
1709
- return db[table].read(result["id"]);
1675
+ result.read = function(columns2) {
1676
+ return db[table].read(result["id"], columns2);
1710
1677
  };
1711
- result.update = function(data) {
1712
- return db[table].update(result["id"], data);
1678
+ result.update = function(data, columns2) {
1679
+ return db[table].update(result["id"], data, columns2);
1713
1680
  };
1714
1681
  result.delete = function() {
1715
1682
  return db[table].delete(result["id"]);
@@ -1723,14 +1690,8 @@ const initObject = (db, schemaTables, table, object) => {
1723
1690
  Object.freeze(result);
1724
1691
  return result;
1725
1692
  };
1726
- function getIds(value) {
1727
- if (Array.isArray(value)) {
1728
- return value.map((item) => getIds(item)).flat();
1729
- }
1730
- if (!isObject(value))
1731
- return [];
1732
- const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1733
- return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
1693
+ function isResponseWithRecords(value) {
1694
+ return isObject(value) && Array.isArray(value.records);
1734
1695
  }
1735
1696
 
1736
1697
  var __accessCheck$3 = (obj, member, msg) => {
@@ -1757,7 +1718,6 @@ class SimpleCache {
1757
1718
  __privateAdd$3(this, _map, void 0);
1758
1719
  __privateSet$3(this, _map, /* @__PURE__ */ new Map());
1759
1720
  this.capacity = options.max ?? 500;
1760
- this.cacheRecords = options.cacheRecords ?? true;
1761
1721
  this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1762
1722
  }
1763
1723
  async getAll() {
@@ -1829,16 +1789,19 @@ class SchemaPlugin extends XataPlugin {
1829
1789
  __privateSet$2(this, _schemaTables$1, schemaTables);
1830
1790
  }
1831
1791
  build(pluginOptions) {
1832
- const db = new Proxy({}, {
1833
- get: (_target, table) => {
1834
- if (!isString(table))
1835
- throw new Error("Invalid table name");
1836
- if (__privateGet$2(this, _tables)[table] === void 0) {
1837
- __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
1792
+ const db = new Proxy(
1793
+ {},
1794
+ {
1795
+ get: (_target, table) => {
1796
+ if (!isString(table))
1797
+ throw new Error("Invalid table name");
1798
+ if (__privateGet$2(this, _tables)[table] === void 0) {
1799
+ __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
1800
+ }
1801
+ return __privateGet$2(this, _tables)[table];
1838
1802
  }
1839
- return __privateGet$2(this, _tables)[table];
1840
1803
  }
1841
- });
1804
+ );
1842
1805
  const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
1843
1806
  for (const table of tableNames) {
1844
1807
  db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
@@ -1908,10 +1871,10 @@ _schemaTables = new WeakMap();
1908
1871
  _search = new WeakSet();
1909
1872
  search_fn = async function(query, options, getFetchProps) {
1910
1873
  const fetchProps = await getFetchProps();
1911
- const { tables, fuzziness, highlight } = options ?? {};
1874
+ const { tables, fuzziness, highlight, prefix } = options ?? {};
1912
1875
  const { records } = await searchBranch({
1913
1876
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1914
- body: { tables, query, fuzziness, highlight },
1877
+ body: { tables, query, fuzziness, prefix, highlight },
1915
1878
  ...fetchProps
1916
1879
  });
1917
1880
  return records;
@@ -1952,9 +1915,13 @@ async function resolveXataBranch(gitBranch, options) {
1952
1915
  const databaseURL = options?.databaseURL || getDatabaseURL();
1953
1916
  const apiKey = options?.apiKey || getAPIKey();
1954
1917
  if (!databaseURL)
1955
- throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
1918
+ throw new Error(
1919
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
1920
+ );
1956
1921
  if (!apiKey)
1957
- throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
1922
+ throw new Error(
1923
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
1924
+ );
1958
1925
  const [protocol, , host, , dbName] = databaseURL.split("/");
1959
1926
  const [workspace] = host.split(".");
1960
1927
  const { fallbackBranch } = getEnvironment();
@@ -1972,9 +1939,13 @@ async function getDatabaseBranch(branch, options) {
1972
1939
  const databaseURL = options?.databaseURL || getDatabaseURL();
1973
1940
  const apiKey = options?.apiKey || getAPIKey();
1974
1941
  if (!databaseURL)
1975
- throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
1942
+ throw new Error(
1943
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
1944
+ );
1976
1945
  if (!apiKey)
1977
- throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
1946
+ throw new Error(
1947
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
1948
+ );
1978
1949
  const [protocol, , host, , database] = databaseURL.split("/");
1979
1950
  const [workspace] = host.split(".");
1980
1951
  const dbBranchName = `${database}:${branch}`;
@@ -2057,7 +2028,7 @@ const buildClient = (plugins) => {
2057
2028
  const fetch = getFetchImplementation(options?.fetch);
2058
2029
  const databaseURL = options?.databaseURL || getDatabaseURL();
2059
2030
  const apiKey = options?.apiKey || getAPIKey();
2060
- const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
2031
+ const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2061
2032
  const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
2062
2033
  if (!databaseURL || !apiKey) {
2063
2034
  throw new Error("Options databaseURL and apiKey are required");
@@ -2103,72 +2074,6 @@ const buildClient = (plugins) => {
2103
2074
  class BaseClient extends buildClient() {
2104
2075
  }
2105
2076
 
2106
- const META = "__";
2107
- const VALUE = "___";
2108
- class Serializer {
2109
- constructor() {
2110
- this.classes = {};
2111
- }
2112
- add(clazz) {
2113
- this.classes[clazz.name] = clazz;
2114
- }
2115
- toJSON(data) {
2116
- function visit(obj) {
2117
- if (Array.isArray(obj))
2118
- return obj.map(visit);
2119
- const type = typeof obj;
2120
- if (type === "undefined")
2121
- return { [META]: "undefined" };
2122
- if (type === "bigint")
2123
- return { [META]: "bigint", [VALUE]: obj.toString() };
2124
- if (obj === null || type !== "object")
2125
- return obj;
2126
- const constructor = obj.constructor;
2127
- const o = { [META]: constructor.name };
2128
- for (const [key, value] of Object.entries(obj)) {
2129
- o[key] = visit(value);
2130
- }
2131
- if (constructor === Date)
2132
- o[VALUE] = obj.toISOString();
2133
- if (constructor === Map)
2134
- o[VALUE] = Object.fromEntries(obj);
2135
- if (constructor === Set)
2136
- o[VALUE] = [...obj];
2137
- return o;
2138
- }
2139
- return JSON.stringify(visit(data));
2140
- }
2141
- fromJSON(json) {
2142
- return JSON.parse(json, (key, value) => {
2143
- if (value && typeof value === "object" && !Array.isArray(value)) {
2144
- const { [META]: clazz, [VALUE]: val, ...rest } = value;
2145
- const constructor = this.classes[clazz];
2146
- if (constructor) {
2147
- return Object.assign(Object.create(constructor.prototype), rest);
2148
- }
2149
- if (clazz === "Date")
2150
- return new Date(val);
2151
- if (clazz === "Set")
2152
- return new Set(val);
2153
- if (clazz === "Map")
2154
- return new Map(Object.entries(val));
2155
- if (clazz === "bigint")
2156
- return BigInt(val);
2157
- if (clazz === "undefined")
2158
- return void 0;
2159
- return rest;
2160
- }
2161
- return value;
2162
- });
2163
- }
2164
- }
2165
- const serialize = () => {
2166
- throw new Error("Not implemented");
2167
- };
2168
- const deserialize = () => {
2169
- throw new Error("Not implemented");
2170
- };
2171
-
2172
2077
  class XataError extends Error {
2173
2078
  constructor(message, status) {
2174
2079
  super(message);
@@ -2189,7 +2094,6 @@ exports.Repository = Repository;
2189
2094
  exports.RestRepository = RestRepository;
2190
2095
  exports.SchemaPlugin = SchemaPlugin;
2191
2096
  exports.SearchPlugin = SearchPlugin;
2192
- exports.Serializer = Serializer;
2193
2097
  exports.SimpleCache = SimpleCache;
2194
2098
  exports.XataApiClient = XataApiClient;
2195
2099
  exports.XataApiPlugin = XataApiPlugin;
@@ -2215,7 +2119,6 @@ exports.deleteTable = deleteTable;
2215
2119
  exports.deleteUser = deleteUser;
2216
2120
  exports.deleteUserAPIKey = deleteUserAPIKey;
2217
2121
  exports.deleteWorkspace = deleteWorkspace;
2218
- exports.deserialize = deserialize;
2219
2122
  exports.endsWith = endsWith;
2220
2123
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
2221
2124
  exports.exists = exists;
@@ -2268,7 +2171,6 @@ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
2268
2171
  exports.resolveBranch = resolveBranch;
2269
2172
  exports.searchBranch = searchBranch;
2270
2173
  exports.searchTable = searchTable;
2271
- exports.serialize = serialize;
2272
2174
  exports.setTableSchema = setTableSchema;
2273
2175
  exports.startsWith = startsWith;
2274
2176
  exports.updateBranchMetadata = updateBranchMetadata;