@xata.io/client 0.0.0-alpha.vf45a2df → 0.0.0-alpha.vf481c73

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
@@ -22,19 +22,66 @@ function toBase64(value) {
22
22
  }
23
23
  }
24
24
 
25
- function getEnvVariable(name) {
25
+ function getEnvironment() {
26
26
  try {
27
- if (isObject(process) && isString(process?.env?.[name])) {
28
- return process.env[name];
27
+ if (isObject(process) && isObject(process.env)) {
28
+ return {
29
+ apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
30
+ databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
31
+ branch: process.env.XATA_BRANCH,
32
+ envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
33
+ fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
34
+ };
29
35
  }
30
36
  } catch (err) {
31
37
  }
32
38
  try {
33
- if (isObject(Deno) && isString(Deno?.env?.get(name))) {
34
- return Deno.env.get(name);
39
+ if (isObject(Deno) && isObject(Deno.env)) {
40
+ return {
41
+ apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
42
+ databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
43
+ branch: Deno.env.get("XATA_BRANCH"),
44
+ envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
45
+ fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
46
+ };
35
47
  }
36
48
  } catch (err) {
37
49
  }
50
+ return {
51
+ apiKey: getGlobalApiKey(),
52
+ databaseURL: getGlobalDatabaseURL(),
53
+ branch: getGlobalBranch(),
54
+ envBranch: void 0,
55
+ fallbackBranch: getGlobalFallbackBranch()
56
+ };
57
+ }
58
+ function getGlobalApiKey() {
59
+ try {
60
+ return XATA_API_KEY;
61
+ } catch (err) {
62
+ return void 0;
63
+ }
64
+ }
65
+ function getGlobalDatabaseURL() {
66
+ try {
67
+ return XATA_DATABASE_URL;
68
+ } catch (err) {
69
+ return void 0;
70
+ }
71
+ }
72
+ function getGlobalBranch() {
73
+ try {
74
+ return XATA_BRANCH;
75
+ } catch (err) {
76
+ return void 0;
77
+ }
78
+ }
79
+ function getGlobalFallbackBranch() {
80
+ try {
81
+ return XATA_FALLBACK_BRANCH;
82
+ } catch (err) {
83
+ return void 0;
84
+ }
38
85
  }
39
86
  async function getGitBranch() {
40
87
  try {
@@ -59,7 +106,8 @@ async function getGitBranch() {
59
106
 
60
107
  function getAPIKey() {
61
108
  try {
62
- return getEnvVariable("XATA_API_KEY") ?? XATA_API_KEY;
109
+ const { apiKey } = getEnvironment();
110
+ return apiKey;
63
111
  } catch (err) {
64
112
  return void 0;
65
113
  }
@@ -74,7 +122,7 @@ function getFetchImplementation(userFetch) {
74
122
  return fetchImpl;
75
123
  }
76
124
 
77
- const VERSION = "0.0.0-alpha.vf45a2df";
125
+ const VERSION = "0.0.0-alpha.vf481c73";
78
126
 
79
127
  class ErrorWithCause extends Error {
80
128
  constructor(message, options) {
@@ -500,7 +548,7 @@ var __privateAdd$7 = (obj, member, value) => {
500
548
  throw TypeError("Cannot add the same private member more than once");
501
549
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
502
550
  };
503
- var __privateSet$6 = (obj, member, value, setter) => {
551
+ var __privateSet$7 = (obj, member, value, setter) => {
504
552
  __accessCheck$7(obj, member, "write to private field");
505
553
  setter ? setter.call(obj, value) : member.set(obj, value);
506
554
  return value;
@@ -515,7 +563,7 @@ class XataApiClient {
515
563
  if (!apiKey) {
516
564
  throw new Error("Could not resolve a valid apiKey");
517
565
  }
518
- __privateSet$6(this, _extraProps, {
566
+ __privateSet$7(this, _extraProps, {
519
567
  apiUrl: getHostUrl(provider, "main"),
520
568
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
521
569
  fetchImpl: getFetchImplementation(options.fetch),
@@ -952,7 +1000,7 @@ var __privateAdd$6 = (obj, member, value) => {
952
1000
  throw TypeError("Cannot add the same private member more than once");
953
1001
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
954
1002
  };
955
- var __privateSet$5 = (obj, member, value, setter) => {
1003
+ var __privateSet$6 = (obj, member, value, setter) => {
956
1004
  __accessCheck$6(obj, member, "write to private field");
957
1005
  setter ? setter.call(obj, value) : member.set(obj, value);
958
1006
  return value;
@@ -961,7 +1009,7 @@ var _query, _page;
961
1009
  class Page {
962
1010
  constructor(query, meta, records = []) {
963
1011
  __privateAdd$6(this, _query, void 0);
964
- __privateSet$5(this, _query, query);
1012
+ __privateSet$6(this, _query, query);
965
1013
  this.meta = meta;
966
1014
  this.records = new RecordArray(this, records);
967
1015
  }
@@ -993,7 +1041,7 @@ const _RecordArray = class extends Array {
993
1041
  constructor(page, overrideRecords) {
994
1042
  super(..._RecordArray.parseConstructorParams(page, overrideRecords));
995
1043
  __privateAdd$6(this, _page, void 0);
996
- __privateSet$5(this, _page, page);
1044
+ __privateSet$6(this, _page, page);
997
1045
  }
998
1046
  static parseConstructorParams(...args) {
999
1047
  if (args.length === 1 && typeof args[0] === "number") {
@@ -1041,7 +1089,7 @@ var __privateAdd$5 = (obj, member, value) => {
1041
1089
  throw TypeError("Cannot add the same private member more than once");
1042
1090
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1043
1091
  };
1044
- var __privateSet$4 = (obj, member, value, setter) => {
1092
+ var __privateSet$5 = (obj, member, value, setter) => {
1045
1093
  __accessCheck$5(obj, member, "write to private field");
1046
1094
  setter ? setter.call(obj, value) : member.set(obj, value);
1047
1095
  return value;
@@ -1054,11 +1102,11 @@ const _Query = class {
1054
1102
  __privateAdd$5(this, _data, { filter: {} });
1055
1103
  this.meta = { page: { cursor: "start", more: true } };
1056
1104
  this.records = new RecordArray(this, []);
1057
- __privateSet$4(this, _table$1, table);
1105
+ __privateSet$5(this, _table$1, table);
1058
1106
  if (repository) {
1059
- __privateSet$4(this, _repository, repository);
1107
+ __privateSet$5(this, _repository, repository);
1060
1108
  } else {
1061
- __privateSet$4(this, _repository, this);
1109
+ __privateSet$5(this, _repository, this);
1062
1110
  }
1063
1111
  const parent = cleanParent(data, rawParent);
1064
1112
  __privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
@@ -1235,7 +1283,7 @@ var __privateAdd$4 = (obj, member, value) => {
1235
1283
  throw TypeError("Cannot add the same private member more than once");
1236
1284
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1237
1285
  };
1238
- var __privateSet$3 = (obj, member, value, setter) => {
1286
+ var __privateSet$4 = (obj, member, value, setter) => {
1239
1287
  __accessCheck$4(obj, member, "write to private field");
1240
1288
  setter ? setter.call(obj, value) : member.set(obj, value);
1241
1289
  return value;
@@ -1244,7 +1292,7 @@ var __privateMethod$2 = (obj, member, method) => {
1244
1292
  __accessCheck$4(obj, member, "access private method");
1245
1293
  return method;
1246
1294
  };
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;
1295
+ 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;
1248
1296
  class Repository extends Query {
1249
1297
  }
1250
1298
  class RestRepository extends Query {
@@ -1261,15 +1309,16 @@ class RestRepository extends Query {
1261
1309
  __privateAdd$4(this, _getCacheRecord);
1262
1310
  __privateAdd$4(this, _setCacheQuery);
1263
1311
  __privateAdd$4(this, _getCacheQuery);
1264
- __privateAdd$4(this, _getSchema$1);
1312
+ __privateAdd$4(this, _getSchemaTables$1);
1265
1313
  __privateAdd$4(this, _table, void 0);
1266
1314
  __privateAdd$4(this, _getFetchProps, void 0);
1267
1315
  __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);
1316
+ __privateAdd$4(this, _schemaTables$2, void 0);
1317
+ __privateSet$4(this, _table, options.table);
1318
+ __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1271
1319
  this.db = options.db;
1272
- __privateSet$3(this, _cache, options.pluginOptions.cache);
1320
+ __privateSet$4(this, _cache, options.pluginOptions.cache);
1321
+ __privateSet$4(this, _schemaTables$2, options.schemaTables);
1273
1322
  }
1274
1323
  async create(a, b) {
1275
1324
  if (Array.isArray(a)) {
@@ -1318,8 +1367,8 @@ class RestRepository extends Query {
1318
1367
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
1319
1368
  ...fetchProps
1320
1369
  });
1321
- const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1322
- return initObject(this.db, schema, __privateGet$4(this, _table), response);
1370
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1371
+ return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1323
1372
  } catch (e) {
1324
1373
  if (isObject(e) && e.status === 404) {
1325
1374
  return null;
@@ -1408,8 +1457,8 @@ class RestRepository extends Query {
1408
1457
  },
1409
1458
  ...fetchProps
1410
1459
  });
1411
- const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1412
- return records.map((item) => initObject(this.db, schema, __privateGet$4(this, _table), item));
1460
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1461
+ return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
1413
1462
  }
1414
1463
  async query(query) {
1415
1464
  const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
@@ -1428,8 +1477,8 @@ class RestRepository extends Query {
1428
1477
  body,
1429
1478
  ...fetchProps
1430
1479
  });
1431
- const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1432
- const records = objects.map((record) => initObject(this.db, schema, __privateGet$4(this, _table), record));
1480
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1481
+ const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
1433
1482
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1434
1483
  return new Page(query, meta, records);
1435
1484
  }
@@ -1437,7 +1486,7 @@ class RestRepository extends Query {
1437
1486
  _table = new WeakMap();
1438
1487
  _getFetchProps = new WeakMap();
1439
1488
  _cache = new WeakMap();
1440
- _schema$1 = new WeakMap();
1489
+ _schemaTables$2 = new WeakMap();
1441
1490
  _insertRecordWithoutId = new WeakSet();
1442
1491
  insertRecordWithoutId_fn = async function(object) {
1443
1492
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
@@ -1571,17 +1620,17 @@ getCacheQuery_fn = async function(query) {
1571
1620
  const hasExpired = result.date.getTime() + ttl < Date.now();
1572
1621
  return hasExpired ? null : result;
1573
1622
  };
1574
- _getSchema$1 = new WeakSet();
1575
- getSchema_fn$1 = async function() {
1576
- if (__privateGet$4(this, _schema$1))
1577
- return __privateGet$4(this, _schema$1);
1623
+ _getSchemaTables$1 = new WeakSet();
1624
+ getSchemaTables_fn$1 = async function() {
1625
+ if (__privateGet$4(this, _schemaTables$2))
1626
+ return __privateGet$4(this, _schemaTables$2);
1578
1627
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1579
1628
  const { schema } = await getBranchDetails({
1580
1629
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1581
1630
  ...fetchProps
1582
1631
  });
1583
- __privateSet$3(this, _schema$1, schema);
1584
- return schema;
1632
+ __privateSet$4(this, _schemaTables$2, schema.tables);
1633
+ return schema.tables;
1585
1634
  };
1586
1635
  const transformObjectLinks = (object) => {
1587
1636
  return Object.entries(object).reduce((acc, [key, value]) => {
@@ -1590,11 +1639,11 @@ const transformObjectLinks = (object) => {
1590
1639
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1591
1640
  }, {});
1592
1641
  };
1593
- const initObject = (db, schema, table, object) => {
1642
+ const initObject = (db, schemaTables, table, object) => {
1594
1643
  const result = {};
1595
1644
  const { xata, ...rest } = object ?? {};
1596
1645
  Object.assign(result, rest);
1597
- const { columns } = schema.tables.find(({ name }) => name === table) ?? {};
1646
+ const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
1598
1647
  if (!columns)
1599
1648
  console.error(`Table ${table} not found in schema`);
1600
1649
  for (const column of columns ?? []) {
@@ -1614,7 +1663,7 @@ const initObject = (db, schema, table, object) => {
1614
1663
  if (!linkTable) {
1615
1664
  console.error(`Failed to parse link for field ${column.name}`);
1616
1665
  } else if (isObject(value)) {
1617
- result[column.name] = initObject(db, schema, linkTable, value);
1666
+ result[column.name] = initObject(db, schemaTables, linkTable, value);
1618
1667
  }
1619
1668
  break;
1620
1669
  }
@@ -1661,7 +1710,7 @@ var __privateAdd$3 = (obj, member, value) => {
1661
1710
  throw TypeError("Cannot add the same private member more than once");
1662
1711
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1663
1712
  };
1664
- var __privateSet$2 = (obj, member, value, setter) => {
1713
+ var __privateSet$3 = (obj, member, value, setter) => {
1665
1714
  __accessCheck$3(obj, member, "write to private field");
1666
1715
  setter ? setter.call(obj, value) : member.set(obj, value);
1667
1716
  return value;
@@ -1670,7 +1719,7 @@ var _map;
1670
1719
  class SimpleCache {
1671
1720
  constructor(options = {}) {
1672
1721
  __privateAdd$3(this, _map, void 0);
1673
- __privateSet$2(this, _map, /* @__PURE__ */ new Map());
1722
+ __privateSet$3(this, _map, /* @__PURE__ */ new Map());
1674
1723
  this.capacity = options.max ?? 500;
1675
1724
  this.cacheRecords = options.cacheRecords ?? true;
1676
1725
  this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
@@ -1730,12 +1779,18 @@ var __privateAdd$2 = (obj, member, value) => {
1730
1779
  throw TypeError("Cannot add the same private member more than once");
1731
1780
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1732
1781
  };
1733
- var _tables;
1782
+ var __privateSet$2 = (obj, member, value, setter) => {
1783
+ __accessCheck$2(obj, member, "write to private field");
1784
+ setter ? setter.call(obj, value) : member.set(obj, value);
1785
+ return value;
1786
+ };
1787
+ var _tables, _schemaTables$1;
1734
1788
  class SchemaPlugin extends XataPlugin {
1735
- constructor(tableNames) {
1789
+ constructor(schemaTables) {
1736
1790
  super();
1737
- this.tableNames = tableNames;
1738
1791
  __privateAdd$2(this, _tables, {});
1792
+ __privateAdd$2(this, _schemaTables$1, void 0);
1793
+ __privateSet$2(this, _schemaTables$1, schemaTables);
1739
1794
  }
1740
1795
  build(pluginOptions) {
1741
1796
  const db = new Proxy({}, {
@@ -1748,13 +1803,15 @@ class SchemaPlugin extends XataPlugin {
1748
1803
  return __privateGet$2(this, _tables)[table];
1749
1804
  }
1750
1805
  });
1751
- for (const table of this.tableNames ?? []) {
1752
- db[table] = new RestRepository({ db, pluginOptions, table });
1806
+ const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
1807
+ for (const table of tableNames) {
1808
+ db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
1753
1809
  }
1754
1810
  return db;
1755
1811
  }
1756
1812
  }
1757
1813
  _tables = new WeakMap();
1814
+ _schemaTables$1 = new WeakMap();
1758
1815
 
1759
1816
  var __accessCheck$1 = (obj, member, msg) => {
1760
1817
  if (!member.has(obj))
@@ -1778,39 +1835,40 @@ var __privateMethod$1 = (obj, member, method) => {
1778
1835
  __accessCheck$1(obj, member, "access private method");
1779
1836
  return method;
1780
1837
  };
1781
- var _schema, _search, search_fn, _getSchema, getSchema_fn;
1838
+ var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
1782
1839
  class SearchPlugin extends XataPlugin {
1783
- constructor(db) {
1840
+ constructor(db, schemaTables) {
1784
1841
  super();
1785
1842
  this.db = db;
1786
1843
  __privateAdd$1(this, _search);
1787
- __privateAdd$1(this, _getSchema);
1788
- __privateAdd$1(this, _schema, void 0);
1844
+ __privateAdd$1(this, _getSchemaTables);
1845
+ __privateAdd$1(this, _schemaTables, void 0);
1846
+ __privateSet$1(this, _schemaTables, schemaTables);
1789
1847
  }
1790
1848
  build({ getFetchProps }) {
1791
1849
  return {
1792
1850
  all: async (query, options = {}) => {
1793
1851
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
1794
- const schema = await __privateMethod$1(this, _getSchema, getSchema_fn).call(this, getFetchProps);
1852
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1795
1853
  return records.map((record) => {
1796
1854
  const { table = "orphan" } = record.xata;
1797
- return { table, record: initObject(this.db, schema, table, record) };
1855
+ return { table, record: initObject(this.db, schemaTables, table, record) };
1798
1856
  });
1799
1857
  },
1800
1858
  byTable: async (query, options = {}) => {
1801
1859
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
1802
- const schema = await __privateMethod$1(this, _getSchema, getSchema_fn).call(this, getFetchProps);
1860
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1803
1861
  return records.reduce((acc, record) => {
1804
1862
  const { table = "orphan" } = record.xata;
1805
1863
  const items = acc[table] ?? [];
1806
- const item = initObject(this.db, schema, table, record);
1864
+ const item = initObject(this.db, schemaTables, table, record);
1807
1865
  return { ...acc, [table]: [...items, item] };
1808
1866
  }, {});
1809
1867
  }
1810
1868
  };
1811
1869
  }
1812
1870
  }
1813
- _schema = new WeakMap();
1871
+ _schemaTables = new WeakMap();
1814
1872
  _search = new WeakSet();
1815
1873
  search_fn = async function(query, options, getFetchProps) {
1816
1874
  const fetchProps = await getFetchProps();
@@ -1822,38 +1880,32 @@ search_fn = async function(query, options, getFetchProps) {
1822
1880
  });
1823
1881
  return records;
1824
1882
  };
1825
- _getSchema = new WeakSet();
1826
- getSchema_fn = async function(getFetchProps) {
1827
- if (__privateGet$1(this, _schema))
1828
- return __privateGet$1(this, _schema);
1883
+ _getSchemaTables = new WeakSet();
1884
+ getSchemaTables_fn = async function(getFetchProps) {
1885
+ if (__privateGet$1(this, _schemaTables))
1886
+ return __privateGet$1(this, _schemaTables);
1829
1887
  const fetchProps = await getFetchProps();
1830
1888
  const { schema } = await getBranchDetails({
1831
1889
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1832
1890
  ...fetchProps
1833
1891
  });
1834
- __privateSet$1(this, _schema, schema);
1835
- return schema;
1892
+ __privateSet$1(this, _schemaTables, schema.tables);
1893
+ return schema.tables;
1836
1894
  };
1837
1895
 
1838
1896
  const isBranchStrategyBuilder = (strategy) => {
1839
1897
  return typeof strategy === "function";
1840
1898
  };
1841
1899
 
1842
- const envBranchNames = [
1843
- "XATA_BRANCH",
1844
- "VERCEL_GIT_COMMIT_REF",
1845
- "CF_PAGES_BRANCH",
1846
- "BRANCH"
1847
- ];
1848
1900
  async function getCurrentBranchName(options) {
1849
- const env = getBranchByEnvVariable();
1850
- if (env) {
1851
- const details = await getDatabaseBranch(env, options);
1901
+ const { branch, envBranch } = getEnvironment();
1902
+ if (branch) {
1903
+ const details = await getDatabaseBranch(branch, options);
1852
1904
  if (details)
1853
- return env;
1854
- console.warn(`Branch ${env} not found in Xata. Ignoring...`);
1905
+ return branch;
1906
+ console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
1855
1907
  }
1856
- const gitBranch = await getGitBranch();
1908
+ const gitBranch = envBranch || await getGitBranch();
1857
1909
  return resolveXataBranch(gitBranch, options);
1858
1910
  }
1859
1911
  async function getCurrentBranchDetails(options) {
@@ -1869,13 +1921,14 @@ async function resolveXataBranch(gitBranch, options) {
1869
1921
  throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
1870
1922
  const [protocol, , host, , dbName] = databaseURL.split("/");
1871
1923
  const [workspace] = host.split(".");
1924
+ const { fallbackBranch } = getEnvironment();
1872
1925
  const { branch } = await resolveBranch({
1873
1926
  apiKey,
1874
1927
  apiUrl: databaseURL,
1875
1928
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1876
1929
  workspacesApiUrl: `${protocol}//${host}`,
1877
1930
  pathParams: { dbName, workspace },
1878
- queryParams: { gitBranch, fallbackBranch: getEnvVariable("XATA_FALLBACK_BRANCH") }
1931
+ queryParams: { gitBranch, fallbackBranch }
1879
1932
  });
1880
1933
  return branch;
1881
1934
  }
@@ -1903,21 +1956,10 @@ async function getDatabaseBranch(branch, options) {
1903
1956
  throw err;
1904
1957
  }
1905
1958
  }
1906
- function getBranchByEnvVariable() {
1907
- for (const name of envBranchNames) {
1908
- const value = getEnvVariable(name);
1909
- if (value) {
1910
- return value;
1911
- }
1912
- }
1913
- try {
1914
- return XATA_BRANCH;
1915
- } catch (err) {
1916
- }
1917
- }
1918
1959
  function getDatabaseURL() {
1919
1960
  try {
1920
- return getEnvVariable("XATA_DATABASE_URL") ?? XATA_DATABASE_URL;
1961
+ const { databaseURL } = getEnvironment();
1962
+ return databaseURL;
1921
1963
  } catch (err) {
1922
1964
  return void 0;
1923
1965
  }
@@ -1948,7 +1990,7 @@ var __privateMethod = (obj, member, method) => {
1948
1990
  const buildClient = (plugins) => {
1949
1991
  var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
1950
1992
  return _a = class {
1951
- constructor(options = {}, tables) {
1993
+ constructor(options = {}, schemaTables) {
1952
1994
  __privateAdd(this, _parseOptions);
1953
1995
  __privateAdd(this, _getFetchProps);
1954
1996
  __privateAdd(this, _evaluateBranch);
@@ -1958,8 +2000,8 @@ const buildClient = (plugins) => {
1958
2000
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
1959
2001
  cache: safeOptions.cache
1960
2002
  };
1961
- const db = new SchemaPlugin(tables).build(pluginOptions);
1962
- const search = new SearchPlugin(db).build(pluginOptions);
2003
+ const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2004
+ const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
1963
2005
  this.db = db;
1964
2006
  this.search = search;
1965
2007
  for (const [key, namespace] of Object.entries(plugins ?? {})) {