@xata.io/client 0.13.4 → 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/dist/index.mjs CHANGED
@@ -13,6 +13,9 @@ function isDefined(value) {
13
13
  function isString(value) {
14
14
  return isDefined(value) && typeof value === "string";
15
15
  }
16
+ function isStringArray(value) {
17
+ return isDefined(value) && Array.isArray(value) && value.every(isString);
18
+ }
16
19
  function toBase64(value) {
17
20
  try {
18
21
  return btoa(value);
@@ -22,35 +25,83 @@ function toBase64(value) {
22
25
  }
23
26
  }
24
27
 
25
- function getEnvVariable(name) {
28
+ function getEnvironment() {
26
29
  try {
27
- if (isObject(process) && isString(process?.env?.[name])) {
28
- return process.env[name];
30
+ if (isObject(process) && isObject(process.env)) {
31
+ return {
32
+ apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
33
+ databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
34
+ branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
35
+ envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
36
+ fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
37
+ };
29
38
  }
30
39
  } catch (err) {
31
40
  }
32
41
  try {
33
- if (isObject(Deno) && isString(Deno?.env?.get(name))) {
34
- return Deno.env.get(name);
42
+ if (isObject(Deno) && isObject(Deno.env)) {
43
+ return {
44
+ apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
45
+ databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
46
+ branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
47
+ envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
48
+ fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
49
+ };
35
50
  }
36
51
  } catch (err) {
37
52
  }
53
+ return {
54
+ apiKey: getGlobalApiKey(),
55
+ databaseURL: getGlobalDatabaseURL(),
56
+ branch: getGlobalBranch(),
57
+ envBranch: void 0,
58
+ fallbackBranch: getGlobalFallbackBranch()
59
+ };
60
+ }
61
+ function getGlobalApiKey() {
62
+ try {
63
+ return XATA_API_KEY;
64
+ } catch (err) {
65
+ return void 0;
66
+ }
67
+ }
68
+ function getGlobalDatabaseURL() {
69
+ try {
70
+ return XATA_DATABASE_URL;
71
+ } catch (err) {
72
+ return void 0;
73
+ }
74
+ }
75
+ function getGlobalBranch() {
76
+ try {
77
+ return XATA_BRANCH;
78
+ } catch (err) {
79
+ return void 0;
80
+ }
81
+ }
82
+ function getGlobalFallbackBranch() {
83
+ try {
84
+ return XATA_FALLBACK_BRANCH;
85
+ } catch (err) {
86
+ return void 0;
87
+ }
38
88
  }
39
89
  async function getGitBranch() {
90
+ const cmd = ["git", "branch", "--show-current"];
91
+ const fullCmd = cmd.join(" ");
92
+ const nodeModule = ["child", "process"].join("_");
93
+ const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
40
94
  try {
41
95
  if (typeof require === "function") {
42
- const req = require;
43
- return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
96
+ return require(nodeModule).execSync(fullCmd, execOptions).trim();
44
97
  }
98
+ const { execSync } = await import(nodeModule);
99
+ return execSync(fullCmd, execOptions).toString().trim();
45
100
  } catch (err) {
46
101
  }
47
102
  try {
48
103
  if (isObject(Deno)) {
49
- const process2 = Deno.run({
50
- cmd: ["git", "branch", "--show-current"],
51
- stdout: "piped",
52
- stderr: "piped"
53
- });
104
+ const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
54
105
  return new TextDecoder().decode(await process2.output()).trim();
55
106
  }
56
107
  } catch (err) {
@@ -59,7 +110,8 @@ async function getGitBranch() {
59
110
 
60
111
  function getAPIKey() {
61
112
  try {
62
- return getEnvVariable("XATA_API_KEY") ?? XATA_API_KEY;
113
+ const { apiKey } = getEnvironment();
114
+ return apiKey;
63
115
  } catch (err) {
64
116
  return void 0;
65
117
  }
@@ -74,7 +126,7 @@ function getFetchImplementation(userFetch) {
74
126
  return fetchImpl;
75
127
  }
76
128
 
77
- const VERSION = "0.13.4";
129
+ const VERSION = "0.16.0";
78
130
 
79
131
  class ErrorWithCause extends Error {
80
132
  constructor(message, options) {
@@ -239,6 +291,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
239
291
  ...variables
240
292
  });
241
293
  const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
294
+ const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
242
295
  const cancelWorkspaceMemberInvite = (variables) => fetch$1({
243
296
  url: "/workspaces/{workspaceId}/invites/{inviteId}",
244
297
  method: "delete",
@@ -287,11 +340,7 @@ const getBranchDetails = (variables) => fetch$1({
287
340
  method: "get",
288
341
  ...variables
289
342
  });
290
- const createBranch = (variables) => fetch$1({
291
- url: "/db/{dbBranchName}",
292
- method: "put",
293
- ...variables
294
- });
343
+ const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
295
344
  const deleteBranch = (variables) => fetch$1({
296
345
  url: "/db/{dbBranchName}",
297
346
  method: "delete",
@@ -365,11 +414,7 @@ const updateColumn = (variables) => fetch$1({
365
414
  method: "patch",
366
415
  ...variables
367
416
  });
368
- const insertRecord = (variables) => fetch$1({
369
- url: "/db/{dbBranchName}/tables/{tableName}/data",
370
- method: "post",
371
- ...variables
372
- });
417
+ const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
373
418
  const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
374
419
  const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
375
420
  const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
@@ -411,6 +456,7 @@ const operationsByTag = {
411
456
  updateWorkspaceMemberRole,
412
457
  removeWorkspaceMember,
413
458
  inviteWorkspaceMember,
459
+ updateWorkspaceMemberInvite,
414
460
  cancelWorkspaceMemberInvite,
415
461
  resendWorkspaceMemberInvite,
416
462
  acceptWorkspaceMemberInvite
@@ -500,7 +546,7 @@ var __privateAdd$7 = (obj, member, value) => {
500
546
  throw TypeError("Cannot add the same private member more than once");
501
547
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
502
548
  };
503
- var __privateSet$6 = (obj, member, value, setter) => {
549
+ var __privateSet$7 = (obj, member, value, setter) => {
504
550
  __accessCheck$7(obj, member, "write to private field");
505
551
  setter ? setter.call(obj, value) : member.set(obj, value);
506
552
  return value;
@@ -515,7 +561,7 @@ class XataApiClient {
515
561
  if (!apiKey) {
516
562
  throw new Error("Could not resolve a valid apiKey");
517
563
  }
518
- __privateSet$6(this, _extraProps, {
564
+ __privateSet$7(this, _extraProps, {
519
565
  apiUrl: getHostUrl(provider, "main"),
520
566
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
521
567
  fetchImpl: getFetchImplementation(options.fetch),
@@ -642,6 +688,13 @@ class WorkspaceApi {
642
688
  ...this.extraProps
643
689
  });
644
690
  }
691
+ updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
692
+ return operationsByTag.workspaces.updateWorkspaceMemberInvite({
693
+ pathParams: { workspaceId, inviteId },
694
+ body: { role },
695
+ ...this.extraProps
696
+ });
697
+ }
645
698
  cancelWorkspaceMemberInvite(workspaceId, inviteId) {
646
699
  return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
647
700
  pathParams: { workspaceId, inviteId },
@@ -856,9 +909,10 @@ class RecordsApi {
856
909
  constructor(extraProps) {
857
910
  this.extraProps = extraProps;
858
911
  }
859
- insertRecord(workspace, database, branch, tableName, record) {
912
+ insertRecord(workspace, database, branch, tableName, record, options = {}) {
860
913
  return operationsByTag.records.insertRecord({
861
914
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
915
+ queryParams: options,
862
916
  body: record,
863
917
  ...this.extraProps
864
918
  });
@@ -887,21 +941,24 @@ class RecordsApi {
887
941
  ...this.extraProps
888
942
  });
889
943
  }
890
- deleteRecord(workspace, database, branch, tableName, recordId) {
944
+ deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
891
945
  return operationsByTag.records.deleteRecord({
892
946
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
947
+ queryParams: options,
893
948
  ...this.extraProps
894
949
  });
895
950
  }
896
951
  getRecord(workspace, database, branch, tableName, recordId, options = {}) {
897
952
  return operationsByTag.records.getRecord({
898
953
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
954
+ queryParams: options,
899
955
  ...this.extraProps
900
956
  });
901
957
  }
902
- bulkInsertTableRecords(workspace, database, branch, tableName, records) {
958
+ bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
903
959
  return operationsByTag.records.bulkInsertTableRecords({
904
960
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
961
+ queryParams: options,
905
962
  body: { records },
906
963
  ...this.extraProps
907
964
  });
@@ -952,7 +1009,7 @@ var __privateAdd$6 = (obj, member, value) => {
952
1009
  throw TypeError("Cannot add the same private member more than once");
953
1010
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
954
1011
  };
955
- var __privateSet$5 = (obj, member, value, setter) => {
1012
+ var __privateSet$6 = (obj, member, value, setter) => {
956
1013
  __accessCheck$6(obj, member, "write to private field");
957
1014
  setter ? setter.call(obj, value) : member.set(obj, value);
958
1015
  return value;
@@ -961,7 +1018,7 @@ var _query, _page;
961
1018
  class Page {
962
1019
  constructor(query, meta, records = []) {
963
1020
  __privateAdd$6(this, _query, void 0);
964
- __privateSet$5(this, _query, query);
1021
+ __privateSet$6(this, _query, query);
965
1022
  this.meta = meta;
966
1023
  this.records = new RecordArray(this, records);
967
1024
  }
@@ -990,10 +1047,10 @@ function isCursorPaginationOptions(options) {
990
1047
  return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
991
1048
  }
992
1049
  const _RecordArray = class extends Array {
993
- constructor(page, overrideRecords) {
994
- super(..._RecordArray.parseConstructorParams(page, overrideRecords));
1050
+ constructor(...args) {
1051
+ super(..._RecordArray.parseConstructorParams(...args));
995
1052
  __privateAdd$6(this, _page, void 0);
996
- __privateSet$5(this, _page, page);
1053
+ __privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
997
1054
  }
998
1055
  static parseConstructorParams(...args) {
999
1056
  if (args.length === 1 && typeof args[0] === "number") {
@@ -1005,6 +1062,12 @@ const _RecordArray = class extends Array {
1005
1062
  }
1006
1063
  return new Array(...args);
1007
1064
  }
1065
+ toArray() {
1066
+ return new Array(...this);
1067
+ }
1068
+ map(callbackfn, thisArg) {
1069
+ return this.toArray().map(callbackfn, thisArg);
1070
+ }
1008
1071
  async nextPage(size, offset) {
1009
1072
  const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
1010
1073
  return new _RecordArray(newPage);
@@ -1041,7 +1104,7 @@ var __privateAdd$5 = (obj, member, value) => {
1041
1104
  throw TypeError("Cannot add the same private member more than once");
1042
1105
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1043
1106
  };
1044
- var __privateSet$4 = (obj, member, value, setter) => {
1107
+ var __privateSet$5 = (obj, member, value, setter) => {
1045
1108
  __accessCheck$5(obj, member, "write to private field");
1046
1109
  setter ? setter.call(obj, value) : member.set(obj, value);
1047
1110
  return value;
@@ -1054,11 +1117,11 @@ const _Query = class {
1054
1117
  __privateAdd$5(this, _data, { filter: {} });
1055
1118
  this.meta = { page: { cursor: "start", more: true } };
1056
1119
  this.records = new RecordArray(this, []);
1057
- __privateSet$4(this, _table$1, table);
1120
+ __privateSet$5(this, _table$1, table);
1058
1121
  if (repository) {
1059
- __privateSet$4(this, _repository, repository);
1122
+ __privateSet$5(this, _repository, repository);
1060
1123
  } else {
1061
- __privateSet$4(this, _repository, this);
1124
+ __privateSet$5(this, _repository, this);
1062
1125
  }
1063
1126
  const parent = cleanParent(data, rawParent);
1064
1127
  __privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
@@ -1235,7 +1298,7 @@ var __privateAdd$4 = (obj, member, value) => {
1235
1298
  throw TypeError("Cannot add the same private member more than once");
1236
1299
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1237
1300
  };
1238
- var __privateSet$3 = (obj, member, value, setter) => {
1301
+ var __privateSet$4 = (obj, member, value, setter) => {
1239
1302
  __accessCheck$4(obj, member, "write to private field");
1240
1303
  setter ? setter.call(obj, value) : member.set(obj, value);
1241
1304
  return value;
@@ -1244,7 +1307,7 @@ var __privateMethod$2 = (obj, member, method) => {
1244
1307
  __accessCheck$4(obj, member, "access private method");
1245
1308
  return method;
1246
1309
  };
1247
- var _table, _getFetchProps, _cache, _schema$1, _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, _getSchema$1, getSchema_fn$1;
1310
+ var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
1248
1311
  class Repository extends Query {
1249
1312
  }
1250
1313
  class RestRepository extends Query {
@@ -1256,90 +1319,68 @@ class RestRepository extends Query {
1256
1319
  __privateAdd$4(this, _updateRecordWithID);
1257
1320
  __privateAdd$4(this, _upsertRecordWithID);
1258
1321
  __privateAdd$4(this, _deleteRecord);
1259
- __privateAdd$4(this, _invalidateCache);
1260
- __privateAdd$4(this, _setCacheRecord);
1261
- __privateAdd$4(this, _getCacheRecord);
1262
1322
  __privateAdd$4(this, _setCacheQuery);
1263
1323
  __privateAdd$4(this, _getCacheQuery);
1264
- __privateAdd$4(this, _getSchema$1);
1324
+ __privateAdd$4(this, _getSchemaTables$1);
1265
1325
  __privateAdd$4(this, _table, void 0);
1266
1326
  __privateAdd$4(this, _getFetchProps, void 0);
1267
1327
  __privateAdd$4(this, _cache, void 0);
1268
- __privateAdd$4(this, _schema$1, void 0);
1269
- __privateSet$3(this, _table, options.table);
1270
- __privateSet$3(this, _getFetchProps, options.pluginOptions.getFetchProps);
1328
+ __privateAdd$4(this, _schemaTables$2, void 0);
1329
+ __privateSet$4(this, _table, options.table);
1330
+ __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1271
1331
  this.db = options.db;
1272
- __privateSet$3(this, _cache, options.pluginOptions.cache);
1332
+ __privateSet$4(this, _cache, options.pluginOptions.cache);
1333
+ __privateSet$4(this, _schemaTables$2, options.schemaTables);
1273
1334
  }
1274
- async create(a, b) {
1335
+ async create(a, b, c) {
1275
1336
  if (Array.isArray(a)) {
1276
1337
  if (a.length === 0)
1277
1338
  return [];
1278
- const [itemsWithoutIds, itemsWithIds, order] = a.reduce(([accWithoutIds, accWithIds, accOrder], item) => {
1279
- const condition = isString(item.id);
1280
- accOrder.push(condition);
1281
- if (condition) {
1282
- accWithIds.push(item);
1283
- } else {
1284
- accWithoutIds.push(item);
1285
- }
1286
- return [accWithoutIds, accWithIds, accOrder];
1287
- }, [[], [], []]);
1288
- const recordsWithoutId = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, itemsWithoutIds);
1289
- await Promise.all(recordsWithoutId.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1290
- if (itemsWithIds.length > 100) {
1291
- console.warn("Bulk create operation with id is not optimized in the Xata API yet, this request might be slow");
1292
- }
1293
- const recordsWithId = await Promise.all(itemsWithIds.map((object) => this.create(object)));
1294
- return order.map((condition) => {
1295
- if (condition) {
1296
- return recordsWithId.shift();
1297
- } else {
1298
- return recordsWithoutId.shift();
1299
- }
1300
- }).filter((record) => !!record);
1339
+ const columns = isStringArray(b) ? b : void 0;
1340
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1301
1341
  }
1302
1342
  if (isString(a) && isObject(b)) {
1303
1343
  if (a === "")
1304
1344
  throw new Error("The id can't be empty");
1305
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1306
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1307
- return record;
1345
+ const columns = isStringArray(c) ? c : void 0;
1346
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1308
1347
  }
1309
1348
  if (isObject(a) && isString(a.id)) {
1310
1349
  if (a.id === "")
1311
1350
  throw new Error("The id can't be empty");
1312
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1313
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1314
- return record;
1351
+ const columns = isStringArray(b) ? b : void 0;
1352
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1315
1353
  }
1316
1354
  if (isObject(a)) {
1317
- const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1318
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1319
- return record;
1355
+ const columns = isStringArray(b) ? b : void 0;
1356
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1320
1357
  }
1321
1358
  throw new Error("Invalid arguments for create method");
1322
1359
  }
1323
- async read(a) {
1360
+ async read(a, b) {
1361
+ const columns = isStringArray(b) ? b : ["*"];
1324
1362
  if (Array.isArray(a)) {
1325
1363
  if (a.length === 0)
1326
1364
  return [];
1327
1365
  const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1328
- return this.getAll({ filter: { id: { $any: ids } } });
1366
+ const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
1367
+ const dictionary = finalObjects.reduce((acc, object) => {
1368
+ acc[object.id] = object;
1369
+ return acc;
1370
+ }, {});
1371
+ return ids.map((id2) => dictionary[id2] ?? null);
1329
1372
  }
1330
1373
  const id = isString(a) ? a : a.id;
1331
1374
  if (isString(id)) {
1332
- const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, id);
1333
- if (cacheRecord)
1334
- return cacheRecord;
1335
1375
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1336
1376
  try {
1337
1377
  const response = await getRecord({
1338
1378
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
1379
+ queryParams: { columns },
1339
1380
  ...fetchProps
1340
1381
  });
1341
- const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1342
- return initObject(this.db, schema, __privateGet$4(this, _table), response);
1382
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1383
+ return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1343
1384
  } catch (e) {
1344
1385
  if (isObject(e) && e.status === 404) {
1345
1386
  return null;
@@ -1347,50 +1388,45 @@ class RestRepository extends Query {
1347
1388
  throw e;
1348
1389
  }
1349
1390
  }
1391
+ return null;
1350
1392
  }
1351
- async update(a, b) {
1393
+ async update(a, b, c) {
1352
1394
  if (Array.isArray(a)) {
1353
1395
  if (a.length === 0)
1354
1396
  return [];
1355
1397
  if (a.length > 100) {
1356
1398
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1357
1399
  }
1358
- return Promise.all(a.map((object) => this.update(object)));
1400
+ const columns = isStringArray(b) ? b : ["*"];
1401
+ return Promise.all(a.map((object) => this.update(object, columns)));
1359
1402
  }
1360
1403
  if (isString(a) && isObject(b)) {
1361
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1362
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1363
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1364
- return record;
1404
+ const columns = isStringArray(c) ? c : void 0;
1405
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1365
1406
  }
1366
1407
  if (isObject(a) && isString(a.id)) {
1367
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1368
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1369
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1370
- return record;
1408
+ const columns = isStringArray(b) ? b : void 0;
1409
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1371
1410
  }
1372
1411
  throw new Error("Invalid arguments for update method");
1373
1412
  }
1374
- async createOrUpdate(a, b) {
1413
+ async createOrUpdate(a, b, c) {
1375
1414
  if (Array.isArray(a)) {
1376
1415
  if (a.length === 0)
1377
1416
  return [];
1378
1417
  if (a.length > 100) {
1379
1418
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1380
1419
  }
1381
- return Promise.all(a.map((object) => this.createOrUpdate(object)));
1420
+ const columns = isStringArray(b) ? b : ["*"];
1421
+ return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1382
1422
  }
1383
1423
  if (isString(a) && isObject(b)) {
1384
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1385
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1386
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1387
- return record;
1424
+ const columns = isStringArray(c) ? c : void 0;
1425
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1388
1426
  }
1389
1427
  if (isObject(a) && isString(a.id)) {
1390
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1391
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1392
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1393
- return record;
1428
+ const columns = isStringArray(c) ? c : void 0;
1429
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1394
1430
  }
1395
1431
  throw new Error("Invalid arguments for createOrUpdate method");
1396
1432
  }
@@ -1406,12 +1442,10 @@ class RestRepository extends Query {
1406
1442
  }
1407
1443
  if (isString(a)) {
1408
1444
  await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1409
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1410
1445
  return;
1411
1446
  }
1412
1447
  if (isObject(a) && isString(a.id)) {
1413
1448
  await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1414
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1415
1449
  return;
1416
1450
  }
1417
1451
  throw new Error("Invalid arguments for delete method");
@@ -1423,13 +1457,15 @@ class RestRepository extends Query {
1423
1457
  body: {
1424
1458
  query,
1425
1459
  fuzziness: options.fuzziness,
1460
+ prefix: options.prefix,
1426
1461
  highlight: options.highlight,
1427
- filter: options.filter
1462
+ filter: options.filter,
1463
+ boosters: options.boosters
1428
1464
  },
1429
1465
  ...fetchProps
1430
1466
  });
1431
- const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1432
- return records.map((item) => initObject(this.db, schema, __privateGet$4(this, _table), item));
1467
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1468
+ return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
1433
1469
  }
1434
1470
  async query(query) {
1435
1471
  const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
@@ -1448,8 +1484,8 @@ class RestRepository extends Query {
1448
1484
  body,
1449
1485
  ...fetchProps
1450
1486
  });
1451
- const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1452
- const records = objects.map((record) => initObject(this.db, schema, __privateGet$4(this, _table), record));
1487
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1488
+ const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
1453
1489
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1454
1490
  return new Page(query, meta, records);
1455
1491
  }
@@ -1457,9 +1493,9 @@ class RestRepository extends Query {
1457
1493
  _table = new WeakMap();
1458
1494
  _getFetchProps = new WeakMap();
1459
1495
  _cache = new WeakMap();
1460
- _schema$1 = new WeakMap();
1496
+ _schemaTables$2 = new WeakMap();
1461
1497
  _insertRecordWithoutId = new WeakSet();
1462
- insertRecordWithoutId_fn = async function(object) {
1498
+ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1463
1499
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1464
1500
  const record = transformObjectLinks(object);
1465
1501
  const response = await insertRecord({
@@ -1468,17 +1504,15 @@ insertRecordWithoutId_fn = async function(object) {
1468
1504
  dbBranchName: "{dbBranch}",
1469
1505
  tableName: __privateGet$4(this, _table)
1470
1506
  },
1507
+ queryParams: { columns },
1471
1508
  body: record,
1472
1509
  ...fetchProps
1473
1510
  });
1474
- const finalObject = await this.read(response.id);
1475
- if (!finalObject) {
1476
- throw new Error("The server failed to save the record");
1477
- }
1478
- return finalObject;
1511
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1512
+ return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1479
1513
  };
1480
1514
  _insertRecordWithId = new WeakSet();
1481
- insertRecordWithId_fn = async function(recordId, object) {
1515
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
1482
1516
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1483
1517
  const record = transformObjectLinks(object);
1484
1518
  const response = await insertRecordWithID({
@@ -1489,56 +1523,52 @@ insertRecordWithId_fn = async function(recordId, object) {
1489
1523
  recordId
1490
1524
  },
1491
1525
  body: record,
1492
- queryParams: { createOnly: true },
1526
+ queryParams: { createOnly: true, columns },
1493
1527
  ...fetchProps
1494
1528
  });
1495
- const finalObject = await this.read(response.id);
1496
- if (!finalObject) {
1497
- throw new Error("The server failed to save the record");
1498
- }
1499
- return finalObject;
1529
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1530
+ return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1500
1531
  };
1501
1532
  _bulkInsertTableRecords = new WeakSet();
1502
- bulkInsertTableRecords_fn = async function(objects) {
1533
+ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1503
1534
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1504
1535
  const records = objects.map((object) => transformObjectLinks(object));
1505
1536
  const response = await bulkInsertTableRecords({
1506
1537
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1538
+ queryParams: { columns },
1507
1539
  body: { records },
1508
1540
  ...fetchProps
1509
1541
  });
1510
- const finalObjects = await this.read(response.recordIDs);
1511
- if (finalObjects.length !== objects.length) {
1512
- throw new Error("The server failed to save some records");
1542
+ if (!isResponseWithRecords(response)) {
1543
+ throw new Error("Request included columns but server didn't include them");
1513
1544
  }
1514
- return finalObjects;
1545
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1546
+ return response.records?.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
1515
1547
  };
1516
1548
  _updateRecordWithID = new WeakSet();
1517
- updateRecordWithID_fn = async function(recordId, object) {
1549
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1518
1550
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1519
1551
  const record = transformObjectLinks(object);
1520
1552
  const response = await updateRecordWithID({
1521
1553
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1554
+ queryParams: { columns },
1522
1555
  body: record,
1523
1556
  ...fetchProps
1524
1557
  });
1525
- const item = await this.read(response.id);
1526
- if (!item)
1527
- throw new Error("The server failed to save the record");
1528
- return item;
1558
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1559
+ return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1529
1560
  };
1530
1561
  _upsertRecordWithID = new WeakSet();
1531
- upsertRecordWithID_fn = async function(recordId, object) {
1562
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1532
1563
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1533
1564
  const response = await upsertRecordWithID({
1534
1565
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1566
+ queryParams: { columns },
1535
1567
  body: object,
1536
1568
  ...fetchProps
1537
1569
  });
1538
- const item = await this.read(response.id);
1539
- if (!item)
1540
- throw new Error("The server failed to save the record");
1541
- return item;
1570
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1571
+ return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1542
1572
  };
1543
1573
  _deleteRecord = new WeakSet();
1544
1574
  deleteRecord_fn = async function(recordId) {
@@ -1548,29 +1578,6 @@ deleteRecord_fn = async function(recordId) {
1548
1578
  ...fetchProps
1549
1579
  });
1550
1580
  };
1551
- _invalidateCache = new WeakSet();
1552
- invalidateCache_fn = async function(recordId) {
1553
- await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1554
- const cacheItems = await __privateGet$4(this, _cache).getAll();
1555
- const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1556
- for (const [key, value] of queries) {
1557
- const ids = getIds(value);
1558
- if (ids.includes(recordId))
1559
- await __privateGet$4(this, _cache).delete(key);
1560
- }
1561
- };
1562
- _setCacheRecord = new WeakSet();
1563
- setCacheRecord_fn = async function(record) {
1564
- if (!__privateGet$4(this, _cache).cacheRecords)
1565
- return;
1566
- await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
1567
- };
1568
- _getCacheRecord = new WeakSet();
1569
- getCacheRecord_fn = async function(recordId) {
1570
- if (!__privateGet$4(this, _cache).cacheRecords)
1571
- return null;
1572
- return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1573
- };
1574
1581
  _setCacheQuery = new WeakSet();
1575
1582
  setCacheQuery_fn = async function(query, meta, records) {
1576
1583
  await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
@@ -1587,17 +1594,17 @@ getCacheQuery_fn = async function(query) {
1587
1594
  const hasExpired = result.date.getTime() + ttl < Date.now();
1588
1595
  return hasExpired ? null : result;
1589
1596
  };
1590
- _getSchema$1 = new WeakSet();
1591
- getSchema_fn$1 = async function() {
1592
- if (__privateGet$4(this, _schema$1))
1593
- return __privateGet$4(this, _schema$1);
1597
+ _getSchemaTables$1 = new WeakSet();
1598
+ getSchemaTables_fn$1 = async function() {
1599
+ if (__privateGet$4(this, _schemaTables$2))
1600
+ return __privateGet$4(this, _schemaTables$2);
1594
1601
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1595
1602
  const { schema } = await getBranchDetails({
1596
1603
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1597
1604
  ...fetchProps
1598
1605
  });
1599
- __privateSet$3(this, _schema$1, schema);
1600
- return schema;
1606
+ __privateSet$4(this, _schemaTables$2, schema.tables);
1607
+ return schema.tables;
1601
1608
  };
1602
1609
  const transformObjectLinks = (object) => {
1603
1610
  return Object.entries(object).reduce((acc, [key, value]) => {
@@ -1606,11 +1613,11 @@ const transformObjectLinks = (object) => {
1606
1613
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1607
1614
  }, {});
1608
1615
  };
1609
- const initObject = (db, schema, table, object) => {
1616
+ const initObject = (db, schemaTables, table, object) => {
1610
1617
  const result = {};
1611
1618
  const { xata, ...rest } = object ?? {};
1612
1619
  Object.assign(result, rest);
1613
- const { columns } = schema.tables.find(({ name }) => name === table) ?? {};
1620
+ const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
1614
1621
  if (!columns)
1615
1622
  console.error(`Table ${table} not found in schema`);
1616
1623
  for (const column of columns ?? []) {
@@ -1630,17 +1637,17 @@ const initObject = (db, schema, table, object) => {
1630
1637
  if (!linkTable) {
1631
1638
  console.error(`Failed to parse link for field ${column.name}`);
1632
1639
  } else if (isObject(value)) {
1633
- result[column.name] = initObject(db, schema, linkTable, value);
1640
+ result[column.name] = initObject(db, schemaTables, linkTable, value);
1634
1641
  }
1635
1642
  break;
1636
1643
  }
1637
1644
  }
1638
1645
  }
1639
- result.read = function() {
1640
- return db[table].read(result["id"]);
1646
+ result.read = function(columns2) {
1647
+ return db[table].read(result["id"], columns2);
1641
1648
  };
1642
- result.update = function(data) {
1643
- return db[table].update(result["id"], data);
1649
+ result.update = function(data, columns2) {
1650
+ return db[table].update(result["id"], data, columns2);
1644
1651
  };
1645
1652
  result.delete = function() {
1646
1653
  return db[table].delete(result["id"]);
@@ -1654,14 +1661,8 @@ const initObject = (db, schema, table, object) => {
1654
1661
  Object.freeze(result);
1655
1662
  return result;
1656
1663
  };
1657
- function getIds(value) {
1658
- if (Array.isArray(value)) {
1659
- return value.map((item) => getIds(item)).flat();
1660
- }
1661
- if (!isObject(value))
1662
- return [];
1663
- const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1664
- return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
1664
+ function isResponseWithRecords(value) {
1665
+ return isObject(value) && Array.isArray(value.records);
1665
1666
  }
1666
1667
 
1667
1668
  var __accessCheck$3 = (obj, member, msg) => {
@@ -1677,7 +1678,7 @@ var __privateAdd$3 = (obj, member, value) => {
1677
1678
  throw TypeError("Cannot add the same private member more than once");
1678
1679
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1679
1680
  };
1680
- var __privateSet$2 = (obj, member, value, setter) => {
1681
+ var __privateSet$3 = (obj, member, value, setter) => {
1681
1682
  __accessCheck$3(obj, member, "write to private field");
1682
1683
  setter ? setter.call(obj, value) : member.set(obj, value);
1683
1684
  return value;
@@ -1686,9 +1687,8 @@ var _map;
1686
1687
  class SimpleCache {
1687
1688
  constructor(options = {}) {
1688
1689
  __privateAdd$3(this, _map, void 0);
1689
- __privateSet$2(this, _map, /* @__PURE__ */ new Map());
1690
+ __privateSet$3(this, _map, /* @__PURE__ */ new Map());
1690
1691
  this.capacity = options.max ?? 500;
1691
- this.cacheRecords = options.cacheRecords ?? true;
1692
1692
  this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1693
1693
  }
1694
1694
  async getAll() {
@@ -1746,12 +1746,18 @@ var __privateAdd$2 = (obj, member, value) => {
1746
1746
  throw TypeError("Cannot add the same private member more than once");
1747
1747
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1748
1748
  };
1749
- var _tables;
1749
+ var __privateSet$2 = (obj, member, value, setter) => {
1750
+ __accessCheck$2(obj, member, "write to private field");
1751
+ setter ? setter.call(obj, value) : member.set(obj, value);
1752
+ return value;
1753
+ };
1754
+ var _tables, _schemaTables$1;
1750
1755
  class SchemaPlugin extends XataPlugin {
1751
- constructor(tableNames) {
1756
+ constructor(schemaTables) {
1752
1757
  super();
1753
- this.tableNames = tableNames;
1754
1758
  __privateAdd$2(this, _tables, {});
1759
+ __privateAdd$2(this, _schemaTables$1, void 0);
1760
+ __privateSet$2(this, _schemaTables$1, schemaTables);
1755
1761
  }
1756
1762
  build(pluginOptions) {
1757
1763
  const db = new Proxy({}, {
@@ -1759,18 +1765,20 @@ class SchemaPlugin extends XataPlugin {
1759
1765
  if (!isString(table))
1760
1766
  throw new Error("Invalid table name");
1761
1767
  if (__privateGet$2(this, _tables)[table] === void 0) {
1762
- __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table });
1768
+ __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
1763
1769
  }
1764
1770
  return __privateGet$2(this, _tables)[table];
1765
1771
  }
1766
1772
  });
1767
- for (const table of this.tableNames ?? []) {
1768
- db[table] = new RestRepository({ db, pluginOptions, table });
1773
+ const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
1774
+ for (const table of tableNames) {
1775
+ db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
1769
1776
  }
1770
1777
  return db;
1771
1778
  }
1772
1779
  }
1773
1780
  _tables = new WeakMap();
1781
+ _schemaTables$1 = new WeakMap();
1774
1782
 
1775
1783
  var __accessCheck$1 = (obj, member, msg) => {
1776
1784
  if (!member.has(obj))
@@ -1794,82 +1802,77 @@ var __privateMethod$1 = (obj, member, method) => {
1794
1802
  __accessCheck$1(obj, member, "access private method");
1795
1803
  return method;
1796
1804
  };
1797
- var _schema, _search, search_fn, _getSchema, getSchema_fn;
1805
+ var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
1798
1806
  class SearchPlugin extends XataPlugin {
1799
- constructor(db) {
1807
+ constructor(db, schemaTables) {
1800
1808
  super();
1801
1809
  this.db = db;
1802
1810
  __privateAdd$1(this, _search);
1803
- __privateAdd$1(this, _getSchema);
1804
- __privateAdd$1(this, _schema, void 0);
1811
+ __privateAdd$1(this, _getSchemaTables);
1812
+ __privateAdd$1(this, _schemaTables, void 0);
1813
+ __privateSet$1(this, _schemaTables, schemaTables);
1805
1814
  }
1806
1815
  build({ getFetchProps }) {
1807
1816
  return {
1808
1817
  all: async (query, options = {}) => {
1809
1818
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
1810
- const schema = await __privateMethod$1(this, _getSchema, getSchema_fn).call(this, getFetchProps);
1819
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1811
1820
  return records.map((record) => {
1812
1821
  const { table = "orphan" } = record.xata;
1813
- return { table, record: initObject(this.db, schema, table, record) };
1822
+ return { table, record: initObject(this.db, schemaTables, table, record) };
1814
1823
  });
1815
1824
  },
1816
1825
  byTable: async (query, options = {}) => {
1817
1826
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
1818
- const schema = await __privateMethod$1(this, _getSchema, getSchema_fn).call(this, getFetchProps);
1827
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1819
1828
  return records.reduce((acc, record) => {
1820
1829
  const { table = "orphan" } = record.xata;
1821
1830
  const items = acc[table] ?? [];
1822
- const item = initObject(this.db, schema, table, record);
1831
+ const item = initObject(this.db, schemaTables, table, record);
1823
1832
  return { ...acc, [table]: [...items, item] };
1824
1833
  }, {});
1825
1834
  }
1826
1835
  };
1827
1836
  }
1828
1837
  }
1829
- _schema = new WeakMap();
1838
+ _schemaTables = new WeakMap();
1830
1839
  _search = new WeakSet();
1831
1840
  search_fn = async function(query, options, getFetchProps) {
1832
1841
  const fetchProps = await getFetchProps();
1833
- const { tables, fuzziness, highlight } = options ?? {};
1842
+ const { tables, fuzziness, highlight, prefix } = options ?? {};
1834
1843
  const { records } = await searchBranch({
1835
1844
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1836
- body: { tables, query, fuzziness, highlight },
1845
+ body: { tables, query, fuzziness, prefix, highlight },
1837
1846
  ...fetchProps
1838
1847
  });
1839
1848
  return records;
1840
1849
  };
1841
- _getSchema = new WeakSet();
1842
- getSchema_fn = async function(getFetchProps) {
1843
- if (__privateGet$1(this, _schema))
1844
- return __privateGet$1(this, _schema);
1850
+ _getSchemaTables = new WeakSet();
1851
+ getSchemaTables_fn = async function(getFetchProps) {
1852
+ if (__privateGet$1(this, _schemaTables))
1853
+ return __privateGet$1(this, _schemaTables);
1845
1854
  const fetchProps = await getFetchProps();
1846
1855
  const { schema } = await getBranchDetails({
1847
1856
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1848
1857
  ...fetchProps
1849
1858
  });
1850
- __privateSet$1(this, _schema, schema);
1851
- return schema;
1859
+ __privateSet$1(this, _schemaTables, schema.tables);
1860
+ return schema.tables;
1852
1861
  };
1853
1862
 
1854
1863
  const isBranchStrategyBuilder = (strategy) => {
1855
1864
  return typeof strategy === "function";
1856
1865
  };
1857
1866
 
1858
- const envBranchNames = [
1859
- "XATA_BRANCH",
1860
- "VERCEL_GIT_COMMIT_REF",
1861
- "CF_PAGES_BRANCH",
1862
- "BRANCH"
1863
- ];
1864
1867
  async function getCurrentBranchName(options) {
1865
- const env = getBranchByEnvVariable();
1866
- if (env) {
1867
- const details = await getDatabaseBranch(env, options);
1868
+ const { branch, envBranch } = getEnvironment();
1869
+ if (branch) {
1870
+ const details = await getDatabaseBranch(branch, options);
1868
1871
  if (details)
1869
- return env;
1870
- console.warn(`Branch ${env} not found in Xata. Ignoring...`);
1872
+ return branch;
1873
+ console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
1871
1874
  }
1872
- const gitBranch = await getGitBranch();
1875
+ const gitBranch = envBranch || await getGitBranch();
1873
1876
  return resolveXataBranch(gitBranch, options);
1874
1877
  }
1875
1878
  async function getCurrentBranchDetails(options) {
@@ -1885,13 +1888,14 @@ async function resolveXataBranch(gitBranch, options) {
1885
1888
  throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
1886
1889
  const [protocol, , host, , dbName] = databaseURL.split("/");
1887
1890
  const [workspace] = host.split(".");
1891
+ const { fallbackBranch } = getEnvironment();
1888
1892
  const { branch } = await resolveBranch({
1889
1893
  apiKey,
1890
1894
  apiUrl: databaseURL,
1891
1895
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1892
1896
  workspacesApiUrl: `${protocol}//${host}`,
1893
1897
  pathParams: { dbName, workspace },
1894
- queryParams: { gitBranch, fallbackBranch: getEnvVariable("XATA_FALLBACK_BRANCH") }
1898
+ queryParams: { gitBranch, fallbackBranch }
1895
1899
  });
1896
1900
  return branch;
1897
1901
  }
@@ -1919,21 +1923,10 @@ async function getDatabaseBranch(branch, options) {
1919
1923
  throw err;
1920
1924
  }
1921
1925
  }
1922
- function getBranchByEnvVariable() {
1923
- for (const name of envBranchNames) {
1924
- const value = getEnvVariable(name);
1925
- if (value) {
1926
- return value;
1927
- }
1928
- }
1929
- try {
1930
- return XATA_BRANCH;
1931
- } catch (err) {
1932
- }
1933
- }
1934
1926
  function getDatabaseURL() {
1935
1927
  try {
1936
- return getEnvVariable("XATA_DATABASE_URL") ?? XATA_DATABASE_URL;
1928
+ const { databaseURL } = getEnvironment();
1929
+ return databaseURL;
1937
1930
  } catch (err) {
1938
1931
  return void 0;
1939
1932
  }
@@ -1964,7 +1957,7 @@ var __privateMethod = (obj, member, method) => {
1964
1957
  const buildClient = (plugins) => {
1965
1958
  var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
1966
1959
  return _a = class {
1967
- constructor(options = {}, tables) {
1960
+ constructor(options = {}, schemaTables) {
1968
1961
  __privateAdd(this, _parseOptions);
1969
1962
  __privateAdd(this, _getFetchProps);
1970
1963
  __privateAdd(this, _evaluateBranch);
@@ -1974,8 +1967,8 @@ const buildClient = (plugins) => {
1974
1967
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
1975
1968
  cache: safeOptions.cache
1976
1969
  };
1977
- const db = new SchemaPlugin(tables).build(pluginOptions);
1978
- const search = new SearchPlugin(db).build(pluginOptions);
1970
+ const db = new SchemaPlugin(schemaTables).build(pluginOptions);
1971
+ const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
1979
1972
  this.db = db;
1980
1973
  this.search = search;
1981
1974
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
@@ -1995,7 +1988,7 @@ const buildClient = (plugins) => {
1995
1988
  const fetch = getFetchImplementation(options?.fetch);
1996
1989
  const databaseURL = options?.databaseURL || getDatabaseURL();
1997
1990
  const apiKey = options?.apiKey || getAPIKey();
1998
- const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
1991
+ const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
1999
1992
  const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
2000
1993
  if (!databaseURL || !apiKey) {
2001
1994
  throw new Error("Options databaseURL and apiKey are required");
@@ -2048,5 +2041,5 @@ class XataError extends Error {
2048
2041
  }
2049
2042
  }
2050
2043
 
2051
- export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
2044
+ export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
2052
2045
  //# sourceMappingURL=index.mjs.map