@xata.io/client 0.14.0 → 0.16.1

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.14.0";
153
+ const VERSION = "0.16.1";
147
154
 
148
155
  class ErrorWithCause extends Error {
149
156
  constructor(message, options) {
@@ -308,6 +315,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
308
315
  ...variables
309
316
  });
310
317
  const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
318
+ const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
311
319
  const cancelWorkspaceMemberInvite = (variables) => fetch$1({
312
320
  url: "/workspaces/{workspaceId}/invites/{inviteId}",
313
321
  method: "delete",
@@ -343,6 +351,11 @@ const deleteDatabase = (variables) => fetch$1({
343
351
  method: "delete",
344
352
  ...variables
345
353
  });
354
+ const getDatabaseMetadata = (variables) => fetch$1({
355
+ url: "/dbs/{dbName}/metadata",
356
+ method: "get",
357
+ ...variables
358
+ });
346
359
  const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
347
360
  const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
348
361
  const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
@@ -356,11 +369,7 @@ const getBranchDetails = (variables) => fetch$1({
356
369
  method: "get",
357
370
  ...variables
358
371
  });
359
- const createBranch = (variables) => fetch$1({
360
- url: "/db/{dbBranchName}",
361
- method: "put",
362
- ...variables
363
- });
372
+ const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
364
373
  const deleteBranch = (variables) => fetch$1({
365
374
  url: "/db/{dbBranchName}",
366
375
  method: "delete",
@@ -434,11 +443,7 @@ const updateColumn = (variables) => fetch$1({
434
443
  method: "patch",
435
444
  ...variables
436
445
  });
437
- const insertRecord = (variables) => fetch$1({
438
- url: "/db/{dbBranchName}/tables/{tableName}/data",
439
- method: "post",
440
- ...variables
441
- });
446
+ const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
442
447
  const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
443
448
  const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
444
449
  const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
@@ -480,6 +485,7 @@ const operationsByTag = {
480
485
  updateWorkspaceMemberRole,
481
486
  removeWorkspaceMember,
482
487
  inviteWorkspaceMember,
488
+ updateWorkspaceMemberInvite,
483
489
  cancelWorkspaceMemberInvite,
484
490
  resendWorkspaceMemberInvite,
485
491
  acceptWorkspaceMemberInvite
@@ -488,6 +494,7 @@ const operationsByTag = {
488
494
  getDatabaseList,
489
495
  createDatabase,
490
496
  deleteDatabase,
497
+ getDatabaseMetadata,
491
498
  getGitBranchesMapping,
492
499
  addGitBranchesEntry,
493
500
  removeGitBranchesEntry,
@@ -711,6 +718,13 @@ class WorkspaceApi {
711
718
  ...this.extraProps
712
719
  });
713
720
  }
721
+ updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
722
+ return operationsByTag.workspaces.updateWorkspaceMemberInvite({
723
+ pathParams: { workspaceId, inviteId },
724
+ body: { role },
725
+ ...this.extraProps
726
+ });
727
+ }
714
728
  cancelWorkspaceMemberInvite(workspaceId, inviteId) {
715
729
  return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
716
730
  pathParams: { workspaceId, inviteId },
@@ -753,6 +767,12 @@ class DatabaseApi {
753
767
  ...this.extraProps
754
768
  });
755
769
  }
770
+ getDatabaseMetadata(workspace, dbName) {
771
+ return operationsByTag.database.getDatabaseMetadata({
772
+ pathParams: { workspace, dbName },
773
+ ...this.extraProps
774
+ });
775
+ }
756
776
  getGitBranchesMapping(workspace, dbName) {
757
777
  return operationsByTag.database.getGitBranchesMapping({
758
778
  pathParams: { workspace, dbName },
@@ -925,9 +945,10 @@ class RecordsApi {
925
945
  constructor(extraProps) {
926
946
  this.extraProps = extraProps;
927
947
  }
928
- insertRecord(workspace, database, branch, tableName, record) {
948
+ insertRecord(workspace, database, branch, tableName, record, options = {}) {
929
949
  return operationsByTag.records.insertRecord({
930
950
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
951
+ queryParams: options,
931
952
  body: record,
932
953
  ...this.extraProps
933
954
  });
@@ -956,21 +977,24 @@ class RecordsApi {
956
977
  ...this.extraProps
957
978
  });
958
979
  }
959
- deleteRecord(workspace, database, branch, tableName, recordId) {
980
+ deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
960
981
  return operationsByTag.records.deleteRecord({
961
982
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
983
+ queryParams: options,
962
984
  ...this.extraProps
963
985
  });
964
986
  }
965
987
  getRecord(workspace, database, branch, tableName, recordId, options = {}) {
966
988
  return operationsByTag.records.getRecord({
967
989
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
990
+ queryParams: options,
968
991
  ...this.extraProps
969
992
  });
970
993
  }
971
- bulkInsertTableRecords(workspace, database, branch, tableName, records) {
994
+ bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
972
995
  return operationsByTag.records.bulkInsertTableRecords({
973
996
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
997
+ queryParams: options,
974
998
  body: { records },
975
999
  ...this.extraProps
976
1000
  });
@@ -1194,7 +1218,12 @@ const _Query = class {
1194
1218
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
1195
1219
  }
1196
1220
  select(columns) {
1197
- return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { columns }, __privateGet$5(this, _data));
1221
+ return new _Query(
1222
+ __privateGet$5(this, _repository),
1223
+ __privateGet$5(this, _table$1),
1224
+ { columns },
1225
+ __privateGet$5(this, _data)
1226
+ );
1198
1227
  }
1199
1228
  getPaginated(options = {}) {
1200
1229
  const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
@@ -1319,7 +1348,7 @@ var __privateMethod$2 = (obj, member, method) => {
1319
1348
  __accessCheck$4(obj, member, "access private method");
1320
1349
  return method;
1321
1350
  };
1322
- 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;
1351
+ var _table, _getFetchProps, _db, _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;
1323
1352
  class Repository extends Query {
1324
1353
  }
1325
1354
  class RestRepository extends Query {
@@ -1331,71 +1360,69 @@ class RestRepository extends Query {
1331
1360
  __privateAdd$4(this, _updateRecordWithID);
1332
1361
  __privateAdd$4(this, _upsertRecordWithID);
1333
1362
  __privateAdd$4(this, _deleteRecord);
1334
- __privateAdd$4(this, _invalidateCache);
1335
- __privateAdd$4(this, _setCacheRecord);
1336
- __privateAdd$4(this, _getCacheRecord);
1337
1363
  __privateAdd$4(this, _setCacheQuery);
1338
1364
  __privateAdd$4(this, _getCacheQuery);
1339
1365
  __privateAdd$4(this, _getSchemaTables$1);
1340
1366
  __privateAdd$4(this, _table, void 0);
1341
1367
  __privateAdd$4(this, _getFetchProps, void 0);
1368
+ __privateAdd$4(this, _db, void 0);
1342
1369
  __privateAdd$4(this, _cache, void 0);
1343
1370
  __privateAdd$4(this, _schemaTables$2, void 0);
1344
1371
  __privateSet$4(this, _table, options.table);
1345
1372
  __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1346
- this.db = options.db;
1373
+ __privateSet$4(this, _db, options.db);
1347
1374
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1348
1375
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
1349
1376
  }
1350
- async create(a, b) {
1377
+ async create(a, b, c) {
1351
1378
  if (Array.isArray(a)) {
1352
1379
  if (a.length === 0)
1353
1380
  return [];
1354
- const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1355
- await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1356
- return records;
1381
+ const columns = isStringArray(b) ? b : void 0;
1382
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1357
1383
  }
1358
1384
  if (isString(a) && isObject(b)) {
1359
1385
  if (a === "")
1360
1386
  throw new Error("The id can't be empty");
1361
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1362
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1363
- return record;
1387
+ const columns = isStringArray(c) ? c : void 0;
1388
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1364
1389
  }
1365
1390
  if (isObject(a) && isString(a.id)) {
1366
1391
  if (a.id === "")
1367
1392
  throw new Error("The id can't be empty");
1368
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1369
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1370
- return record;
1393
+ const columns = isStringArray(b) ? b : void 0;
1394
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1371
1395
  }
1372
1396
  if (isObject(a)) {
1373
- const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1374
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1375
- return record;
1397
+ const columns = isStringArray(b) ? b : void 0;
1398
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1376
1399
  }
1377
1400
  throw new Error("Invalid arguments for create method");
1378
1401
  }
1379
- async read(a) {
1402
+ async read(a, b) {
1403
+ const columns = isStringArray(b) ? b : ["*"];
1380
1404
  if (Array.isArray(a)) {
1381
1405
  if (a.length === 0)
1382
1406
  return [];
1383
1407
  const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1384
- return this.getAll({ filter: { id: { $any: ids } } });
1408
+ const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
1409
+ const dictionary = finalObjects.reduce((acc, object) => {
1410
+ acc[object.id] = object;
1411
+ return acc;
1412
+ }, {});
1413
+ return ids.map((id2) => dictionary[id2] ?? null);
1385
1414
  }
1386
1415
  const id = isString(a) ? a : a.id;
1387
1416
  if (isString(id)) {
1388
- const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, id);
1389
- if (cacheRecord)
1390
- return cacheRecord;
1391
1417
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1392
1418
  try {
1393
1419
  const response = await getRecord({
1394
1420
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
1421
+ queryParams: { columns },
1395
1422
  ...fetchProps
1396
1423
  });
1397
1424
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1398
- return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1425
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1399
1426
  } catch (e) {
1400
1427
  if (isObject(e) && e.status === 404) {
1401
1428
  return null;
@@ -1403,50 +1430,45 @@ class RestRepository extends Query {
1403
1430
  throw e;
1404
1431
  }
1405
1432
  }
1433
+ return null;
1406
1434
  }
1407
- async update(a, b) {
1435
+ async update(a, b, c) {
1408
1436
  if (Array.isArray(a)) {
1409
1437
  if (a.length === 0)
1410
1438
  return [];
1411
1439
  if (a.length > 100) {
1412
1440
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1413
1441
  }
1414
- return Promise.all(a.map((object) => this.update(object)));
1442
+ const columns = isStringArray(b) ? b : ["*"];
1443
+ return Promise.all(a.map((object) => this.update(object, columns)));
1415
1444
  }
1416
1445
  if (isString(a) && isObject(b)) {
1417
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1418
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1419
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1420
- return record;
1446
+ const columns = isStringArray(c) ? c : void 0;
1447
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1421
1448
  }
1422
1449
  if (isObject(a) && isString(a.id)) {
1423
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1424
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1425
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1426
- return record;
1450
+ const columns = isStringArray(b) ? b : void 0;
1451
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1427
1452
  }
1428
1453
  throw new Error("Invalid arguments for update method");
1429
1454
  }
1430
- async createOrUpdate(a, b) {
1455
+ async createOrUpdate(a, b, c) {
1431
1456
  if (Array.isArray(a)) {
1432
1457
  if (a.length === 0)
1433
1458
  return [];
1434
1459
  if (a.length > 100) {
1435
1460
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1436
1461
  }
1437
- return Promise.all(a.map((object) => this.createOrUpdate(object)));
1462
+ const columns = isStringArray(b) ? b : ["*"];
1463
+ return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1438
1464
  }
1439
1465
  if (isString(a) && isObject(b)) {
1440
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1441
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1442
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1443
- return record;
1466
+ const columns = isStringArray(c) ? c : void 0;
1467
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1444
1468
  }
1445
1469
  if (isObject(a) && isString(a.id)) {
1446
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1447
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1448
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1449
- return record;
1470
+ const columns = isStringArray(c) ? c : void 0;
1471
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1450
1472
  }
1451
1473
  throw new Error("Invalid arguments for createOrUpdate method");
1452
1474
  }
@@ -1462,12 +1484,10 @@ class RestRepository extends Query {
1462
1484
  }
1463
1485
  if (isString(a)) {
1464
1486
  await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1465
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1466
1487
  return;
1467
1488
  }
1468
1489
  if (isObject(a) && isString(a.id)) {
1469
1490
  await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1470
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1471
1491
  return;
1472
1492
  }
1473
1493
  throw new Error("Invalid arguments for delete method");
@@ -1479,13 +1499,15 @@ class RestRepository extends Query {
1479
1499
  body: {
1480
1500
  query,
1481
1501
  fuzziness: options.fuzziness,
1502
+ prefix: options.prefix,
1482
1503
  highlight: options.highlight,
1483
- filter: options.filter
1504
+ filter: options.filter,
1505
+ boosters: options.boosters
1484
1506
  },
1485
1507
  ...fetchProps
1486
1508
  });
1487
1509
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1488
- return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
1510
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1489
1511
  }
1490
1512
  async query(query) {
1491
1513
  const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
@@ -1505,17 +1527,18 @@ class RestRepository extends Query {
1505
1527
  ...fetchProps
1506
1528
  });
1507
1529
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1508
- const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
1530
+ const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1509
1531
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1510
1532
  return new Page(query, meta, records);
1511
1533
  }
1512
1534
  }
1513
1535
  _table = new WeakMap();
1514
1536
  _getFetchProps = new WeakMap();
1537
+ _db = new WeakMap();
1515
1538
  _cache = new WeakMap();
1516
1539
  _schemaTables$2 = new WeakMap();
1517
1540
  _insertRecordWithoutId = new WeakSet();
1518
- insertRecordWithoutId_fn = async function(object) {
1541
+ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1519
1542
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1520
1543
  const record = transformObjectLinks(object);
1521
1544
  const response = await insertRecord({
@@ -1524,17 +1547,15 @@ insertRecordWithoutId_fn = async function(object) {
1524
1547
  dbBranchName: "{dbBranch}",
1525
1548
  tableName: __privateGet$4(this, _table)
1526
1549
  },
1550
+ queryParams: { columns },
1527
1551
  body: record,
1528
1552
  ...fetchProps
1529
1553
  });
1530
- const finalObject = await this.read(response.id);
1531
- if (!finalObject) {
1532
- throw new Error("The server failed to save the record");
1533
- }
1534
- return finalObject;
1554
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1555
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1535
1556
  };
1536
1557
  _insertRecordWithId = new WeakSet();
1537
- insertRecordWithId_fn = async function(recordId, object) {
1558
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
1538
1559
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1539
1560
  const record = transformObjectLinks(object);
1540
1561
  const response = await insertRecordWithID({
@@ -1545,60 +1566,52 @@ insertRecordWithId_fn = async function(recordId, object) {
1545
1566
  recordId
1546
1567
  },
1547
1568
  body: record,
1548
- queryParams: { createOnly: true },
1569
+ queryParams: { createOnly: true, columns },
1549
1570
  ...fetchProps
1550
1571
  });
1551
- const finalObject = await this.read(response.id);
1552
- if (!finalObject) {
1553
- throw new Error("The server failed to save the record");
1554
- }
1555
- return finalObject;
1572
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1573
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1556
1574
  };
1557
1575
  _bulkInsertTableRecords = new WeakSet();
1558
- bulkInsertTableRecords_fn = async function(objects) {
1576
+ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1559
1577
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1560
1578
  const records = objects.map((object) => transformObjectLinks(object));
1561
- const { recordIDs } = await bulkInsertTableRecords({
1579
+ const response = await bulkInsertTableRecords({
1562
1580
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1581
+ queryParams: { columns },
1563
1582
  body: { records },
1564
1583
  ...fetchProps
1565
1584
  });
1566
- const finalObjects = await this.read(recordIDs);
1567
- if (finalObjects.length !== objects.length) {
1568
- throw new Error("The server failed to save some records");
1585
+ if (!isResponseWithRecords(response)) {
1586
+ throw new Error("Request included columns but server didn't include them");
1569
1587
  }
1570
- const dictionary = finalObjects.reduce((acc, object) => {
1571
- acc[object.id] = object;
1572
- return acc;
1573
- }, {});
1574
- return recordIDs.map((id) => dictionary[id]);
1588
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1589
+ return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1575
1590
  };
1576
1591
  _updateRecordWithID = new WeakSet();
1577
- updateRecordWithID_fn = async function(recordId, object) {
1592
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1578
1593
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1579
1594
  const record = transformObjectLinks(object);
1580
1595
  const response = await updateRecordWithID({
1581
1596
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1597
+ queryParams: { columns },
1582
1598
  body: record,
1583
1599
  ...fetchProps
1584
1600
  });
1585
- const item = await this.read(response.id);
1586
- if (!item)
1587
- throw new Error("The server failed to save the record");
1588
- return item;
1601
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1602
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1589
1603
  };
1590
1604
  _upsertRecordWithID = new WeakSet();
1591
- upsertRecordWithID_fn = async function(recordId, object) {
1605
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1592
1606
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1593
1607
  const response = await upsertRecordWithID({
1594
1608
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1609
+ queryParams: { columns },
1595
1610
  body: object,
1596
1611
  ...fetchProps
1597
1612
  });
1598
- const item = await this.read(response.id);
1599
- if (!item)
1600
- throw new Error("The server failed to save the record");
1601
- return item;
1613
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1614
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1602
1615
  };
1603
1616
  _deleteRecord = new WeakSet();
1604
1617
  deleteRecord_fn = async function(recordId) {
@@ -1608,29 +1621,6 @@ deleteRecord_fn = async function(recordId) {
1608
1621
  ...fetchProps
1609
1622
  });
1610
1623
  };
1611
- _invalidateCache = new WeakSet();
1612
- invalidateCache_fn = async function(recordId) {
1613
- await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1614
- const cacheItems = await __privateGet$4(this, _cache).getAll();
1615
- const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1616
- for (const [key, value] of queries) {
1617
- const ids = getIds(value);
1618
- if (ids.includes(recordId))
1619
- await __privateGet$4(this, _cache).delete(key);
1620
- }
1621
- };
1622
- _setCacheRecord = new WeakSet();
1623
- setCacheRecord_fn = async function(record) {
1624
- if (!__privateGet$4(this, _cache).cacheRecords)
1625
- return;
1626
- await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
1627
- };
1628
- _getCacheRecord = new WeakSet();
1629
- getCacheRecord_fn = async function(recordId) {
1630
- if (!__privateGet$4(this, _cache).cacheRecords)
1631
- return null;
1632
- return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1633
- };
1634
1624
  _setCacheQuery = new WeakSet();
1635
1625
  setCacheQuery_fn = async function(query, meta, records) {
1636
1626
  await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
@@ -1696,11 +1686,11 @@ const initObject = (db, schemaTables, table, object) => {
1696
1686
  }
1697
1687
  }
1698
1688
  }
1699
- result.read = function() {
1700
- return db[table].read(result["id"]);
1689
+ result.read = function(columns2) {
1690
+ return db[table].read(result["id"], columns2);
1701
1691
  };
1702
- result.update = function(data) {
1703
- return db[table].update(result["id"], data);
1692
+ result.update = function(data, columns2) {
1693
+ return db[table].update(result["id"], data, columns2);
1704
1694
  };
1705
1695
  result.delete = function() {
1706
1696
  return db[table].delete(result["id"]);
@@ -1714,14 +1704,8 @@ const initObject = (db, schemaTables, table, object) => {
1714
1704
  Object.freeze(result);
1715
1705
  return result;
1716
1706
  };
1717
- function getIds(value) {
1718
- if (Array.isArray(value)) {
1719
- return value.map((item) => getIds(item)).flat();
1720
- }
1721
- if (!isObject(value))
1722
- return [];
1723
- const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1724
- return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
1707
+ function isResponseWithRecords(value) {
1708
+ return isObject(value) && Array.isArray(value.records);
1725
1709
  }
1726
1710
 
1727
1711
  var __accessCheck$3 = (obj, member, msg) => {
@@ -1748,7 +1732,6 @@ class SimpleCache {
1748
1732
  __privateAdd$3(this, _map, void 0);
1749
1733
  __privateSet$3(this, _map, /* @__PURE__ */ new Map());
1750
1734
  this.capacity = options.max ?? 500;
1751
- this.cacheRecords = options.cacheRecords ?? true;
1752
1735
  this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1753
1736
  }
1754
1737
  async getAll() {
@@ -1820,16 +1803,19 @@ class SchemaPlugin extends XataPlugin {
1820
1803
  __privateSet$2(this, _schemaTables$1, schemaTables);
1821
1804
  }
1822
1805
  build(pluginOptions) {
1823
- const db = new Proxy({}, {
1824
- get: (_target, table) => {
1825
- if (!isString(table))
1826
- throw new Error("Invalid table name");
1827
- if (__privateGet$2(this, _tables)[table] === void 0) {
1828
- __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
1806
+ const db = new Proxy(
1807
+ {},
1808
+ {
1809
+ get: (_target, table) => {
1810
+ if (!isString(table))
1811
+ throw new Error("Invalid table name");
1812
+ if (__privateGet$2(this, _tables)[table] === void 0) {
1813
+ __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
1814
+ }
1815
+ return __privateGet$2(this, _tables)[table];
1829
1816
  }
1830
- return __privateGet$2(this, _tables)[table];
1831
1817
  }
1832
- });
1818
+ );
1833
1819
  const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
1834
1820
  for (const table of tableNames) {
1835
1821
  db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
@@ -1899,10 +1885,10 @@ _schemaTables = new WeakMap();
1899
1885
  _search = new WeakSet();
1900
1886
  search_fn = async function(query, options, getFetchProps) {
1901
1887
  const fetchProps = await getFetchProps();
1902
- const { tables, fuzziness, highlight } = options ?? {};
1888
+ const { tables, fuzziness, highlight, prefix } = options ?? {};
1903
1889
  const { records } = await searchBranch({
1904
1890
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1905
- body: { tables, query, fuzziness, highlight },
1891
+ body: { tables, query, fuzziness, prefix, highlight },
1906
1892
  ...fetchProps
1907
1893
  });
1908
1894
  return records;
@@ -1943,9 +1929,13 @@ async function resolveXataBranch(gitBranch, options) {
1943
1929
  const databaseURL = options?.databaseURL || getDatabaseURL();
1944
1930
  const apiKey = options?.apiKey || getAPIKey();
1945
1931
  if (!databaseURL)
1946
- throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
1932
+ throw new Error(
1933
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
1934
+ );
1947
1935
  if (!apiKey)
1948
- throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
1936
+ throw new Error(
1937
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
1938
+ );
1949
1939
  const [protocol, , host, , dbName] = databaseURL.split("/");
1950
1940
  const [workspace] = host.split(".");
1951
1941
  const { fallbackBranch } = getEnvironment();
@@ -1963,9 +1953,13 @@ async function getDatabaseBranch(branch, options) {
1963
1953
  const databaseURL = options?.databaseURL || getDatabaseURL();
1964
1954
  const apiKey = options?.apiKey || getAPIKey();
1965
1955
  if (!databaseURL)
1966
- throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
1956
+ throw new Error(
1957
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
1958
+ );
1967
1959
  if (!apiKey)
1968
- throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
1960
+ throw new Error(
1961
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
1962
+ );
1969
1963
  const [protocol, , host, , database] = databaseURL.split("/");
1970
1964
  const [workspace] = host.split(".");
1971
1965
  const dbBranchName = `${database}:${branch}`;
@@ -2015,14 +2009,16 @@ var __privateMethod = (obj, member, method) => {
2015
2009
  return method;
2016
2010
  };
2017
2011
  const buildClient = (plugins) => {
2018
- var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
2012
+ var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
2019
2013
  return _a = class {
2020
2014
  constructor(options = {}, schemaTables) {
2021
2015
  __privateAdd(this, _parseOptions);
2022
2016
  __privateAdd(this, _getFetchProps);
2023
2017
  __privateAdd(this, _evaluateBranch);
2024
2018
  __privateAdd(this, _branch, void 0);
2019
+ __privateAdd(this, _options, void 0);
2025
2020
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
2021
+ __privateSet(this, _options, safeOptions);
2026
2022
  const pluginOptions = {
2027
2023
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
2028
2024
  cache: safeOptions.cache
@@ -2044,22 +2040,22 @@ const buildClient = (plugins) => {
2044
2040
  }
2045
2041
  }
2046
2042
  }
2047
- }, _branch = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
2043
+ async getConfig() {
2044
+ const databaseURL = __privateGet(this, _options).databaseURL;
2045
+ const branch = await __privateGet(this, _options).branch();
2046
+ return { databaseURL, branch };
2047
+ }
2048
+ }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
2048
2049
  const fetch = getFetchImplementation(options?.fetch);
2049
2050
  const databaseURL = options?.databaseURL || getDatabaseURL();
2050
2051
  const apiKey = options?.apiKey || getAPIKey();
2051
- const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
2052
+ const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2052
2053
  const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
2053
2054
  if (!databaseURL || !apiKey) {
2054
2055
  throw new Error("Options databaseURL and apiKey are required");
2055
2056
  }
2056
2057
  return { fetch, databaseURL, apiKey, branch, cache };
2057
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
2058
- fetch,
2059
- apiKey,
2060
- databaseURL,
2061
- branch
2062
- }) {
2058
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch }) {
2063
2059
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2064
2060
  if (!branchValue)
2065
2061
  throw new Error("Unable to resolve branch value");
@@ -2094,6 +2090,88 @@ const buildClient = (plugins) => {
2094
2090
  class BaseClient extends buildClient() {
2095
2091
  }
2096
2092
 
2093
+ const META = "__";
2094
+ const VALUE = "___";
2095
+ class Serializer {
2096
+ constructor() {
2097
+ this.classes = {};
2098
+ }
2099
+ add(clazz) {
2100
+ this.classes[clazz.name] = clazz;
2101
+ }
2102
+ toJSON(data) {
2103
+ function visit(obj) {
2104
+ if (Array.isArray(obj))
2105
+ return obj.map(visit);
2106
+ const type = typeof obj;
2107
+ if (type === "undefined")
2108
+ return { [META]: "undefined" };
2109
+ if (type === "bigint")
2110
+ return { [META]: "bigint", [VALUE]: obj.toString() };
2111
+ if (obj === null || type !== "object")
2112
+ return obj;
2113
+ const constructor = obj.constructor;
2114
+ const o = { [META]: constructor.name };
2115
+ for (const [key, value] of Object.entries(obj)) {
2116
+ o[key] = visit(value);
2117
+ }
2118
+ if (constructor === Date)
2119
+ o[VALUE] = obj.toISOString();
2120
+ if (constructor === Map)
2121
+ o[VALUE] = Object.fromEntries(obj);
2122
+ if (constructor === Set)
2123
+ o[VALUE] = [...obj];
2124
+ return o;
2125
+ }
2126
+ return JSON.stringify(visit(data));
2127
+ }
2128
+ fromJSON(json) {
2129
+ return JSON.parse(json, (key, value) => {
2130
+ if (value && typeof value === "object" && !Array.isArray(value)) {
2131
+ const { [META]: clazz, [VALUE]: val, ...rest } = value;
2132
+ const constructor = this.classes[clazz];
2133
+ if (constructor) {
2134
+ return Object.assign(Object.create(constructor.prototype), rest);
2135
+ }
2136
+ if (clazz === "Date")
2137
+ return new Date(val);
2138
+ if (clazz === "Set")
2139
+ return new Set(val);
2140
+ if (clazz === "Map")
2141
+ return new Map(Object.entries(val));
2142
+ if (clazz === "bigint")
2143
+ return BigInt(val);
2144
+ if (clazz === "undefined")
2145
+ return void 0;
2146
+ return rest;
2147
+ }
2148
+ return value;
2149
+ });
2150
+ }
2151
+ }
2152
+ const defaultSerializer = new Serializer();
2153
+ const serialize = (data) => {
2154
+ return defaultSerializer.toJSON(data);
2155
+ };
2156
+ const deserialize = (json) => {
2157
+ return defaultSerializer.fromJSON(json);
2158
+ };
2159
+
2160
+ function buildWorkerRunner(config) {
2161
+ return function xataWorker(name, _worker) {
2162
+ return async (...args) => {
2163
+ const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
2164
+ const result = await fetch(url, {
2165
+ method: "POST",
2166
+ headers: { "Content-Type": "application/json" },
2167
+ body: serialize({ args })
2168
+ });
2169
+ const text = await result.text();
2170
+ return deserialize(text);
2171
+ };
2172
+ };
2173
+ }
2174
+
2097
2175
  class XataError extends Error {
2098
2176
  constructor(message, status) {
2099
2177
  super(message);
@@ -2114,6 +2192,7 @@ exports.Repository = Repository;
2114
2192
  exports.RestRepository = RestRepository;
2115
2193
  exports.SchemaPlugin = SchemaPlugin;
2116
2194
  exports.SearchPlugin = SearchPlugin;
2195
+ exports.Serializer = Serializer;
2117
2196
  exports.SimpleCache = SimpleCache;
2118
2197
  exports.XataApiClient = XataApiClient;
2119
2198
  exports.XataApiPlugin = XataApiPlugin;
@@ -2123,6 +2202,7 @@ exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
2123
2202
  exports.addGitBranchesEntry = addGitBranchesEntry;
2124
2203
  exports.addTableColumn = addTableColumn;
2125
2204
  exports.buildClient = buildClient;
2205
+ exports.buildWorkerRunner = buildWorkerRunner;
2126
2206
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
2127
2207
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
2128
2208
  exports.contains = contains;
@@ -2139,6 +2219,7 @@ exports.deleteTable = deleteTable;
2139
2219
  exports.deleteUser = deleteUser;
2140
2220
  exports.deleteUserAPIKey = deleteUserAPIKey;
2141
2221
  exports.deleteWorkspace = deleteWorkspace;
2222
+ exports.deserialize = deserialize;
2142
2223
  exports.endsWith = endsWith;
2143
2224
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
2144
2225
  exports.exists = exists;
@@ -2154,6 +2235,7 @@ exports.getColumn = getColumn;
2154
2235
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
2155
2236
  exports.getCurrentBranchName = getCurrentBranchName;
2156
2237
  exports.getDatabaseList = getDatabaseList;
2238
+ exports.getDatabaseMetadata = getDatabaseMetadata;
2157
2239
  exports.getDatabaseURL = getDatabaseURL;
2158
2240
  exports.getGitBranchesMapping = getGitBranchesMapping;
2159
2241
  exports.getRecord = getRecord;
@@ -2191,6 +2273,7 @@ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
2191
2273
  exports.resolveBranch = resolveBranch;
2192
2274
  exports.searchBranch = searchBranch;
2193
2275
  exports.searchTable = searchTable;
2276
+ exports.serialize = serialize;
2194
2277
  exports.setTableSchema = setTableSchema;
2195
2278
  exports.startsWith = startsWith;
2196
2279
  exports.updateBranchMetadata = updateBranchMetadata;
@@ -2199,6 +2282,7 @@ exports.updateRecordWithID = updateRecordWithID;
2199
2282
  exports.updateTable = updateTable;
2200
2283
  exports.updateUser = updateUser;
2201
2284
  exports.updateWorkspace = updateWorkspace;
2285
+ exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
2202
2286
  exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
2203
2287
  exports.upsertRecordWithID = upsertRecordWithID;
2204
2288
  //# sourceMappingURL=index.cjs.map