@xata.io/client 0.10.0 → 0.10.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/.eslintrc.cjs CHANGED
@@ -6,8 +6,7 @@ module.exports = {
6
6
  project: 'packages/client/tsconfig.json'
7
7
  },
8
8
  rules: {
9
- '@typescript-eslint/no-explicit-any': 'off',
10
- '@typescript-eslint/ban-types': 'off',
11
9
  '@typescript-eslint/no-floating-promises': 'error',
10
+ "@typescript-eslint/strict-boolean-expressions": ["error", { allowNullableString: true, allowNullableObject: true }],
12
11
  }
13
12
  };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.10.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#271](https://github.com/xataio/client-ts/pull/271) [`0bb17b8`](https://github.com/xataio/client-ts/commit/0bb17b88d49f1c8be32d2d6b0b3a5918890876cb) Thanks [@SferaDev](https://github.com/SferaDev)! - Link and resolve branches from git
8
+
3
9
  ## 0.10.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -1081,7 +1081,7 @@ const _Query = class {
1081
1081
  }
1082
1082
  async getFirst(options = {}) {
1083
1083
  const records = await this.getMany({ ...options, pagination: { size: 1 } });
1084
- return records[0] || null;
1084
+ return records[0] ?? null;
1085
1085
  }
1086
1086
  cache(ttl) {
1087
1087
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
@@ -1311,7 +1311,7 @@ class RestRepository extends Query {
1311
1311
  const data = query.getQueryOptions();
1312
1312
  const body = {
1313
1313
  filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1314
- sort: data.sort ? buildSortFilter(data.sort) : void 0,
1314
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1315
1315
  page: data.pagination,
1316
1316
  columns: data.columns
1317
1317
  };
@@ -1501,7 +1501,7 @@ const initObject = (db, schema, table, object) => {
1501
1501
  const linkTable = column.link?.table;
1502
1502
  if (!linkTable) {
1503
1503
  console.error(`Failed to parse link for field ${column.name}`);
1504
- } else if (value && isObject(value)) {
1504
+ } else if (isObject(value)) {
1505
1505
  result[column.name] = initObject(db, schema, linkTable, value);
1506
1506
  }
1507
1507
  break;
@@ -1627,7 +1627,7 @@ class SchemaPlugin extends XataPlugin {
1627
1627
  get: (_target, table) => {
1628
1628
  if (!isString(table))
1629
1629
  throw new Error("Invalid table name");
1630
- if (!__privateGet$2(this, _tables)[table]) {
1630
+ if (__privateGet$2(this, _tables)[table] === void 0) {
1631
1631
  __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table });
1632
1632
  }
1633
1633
  return __privateGet$2(this, _tables)[table];
@@ -1730,30 +1730,39 @@ const envBranchNames = [
1730
1730
  "CF_PAGES_BRANCH",
1731
1731
  "BRANCH"
1732
1732
  ];
1733
- const defaultBranch = "main";
1734
1733
  async function getCurrentBranchName(options) {
1735
- const env = await getBranchByEnvVariable();
1736
- if (env)
1737
- return env;
1738
- const branch = await getGitBranch();
1739
- if (!branch)
1740
- return defaultBranch;
1741
- const details = await getDatabaseBranch(branch, options);
1742
- if (details)
1743
- return branch;
1744
- return defaultBranch;
1734
+ const env = getBranchByEnvVariable();
1735
+ if (env) {
1736
+ const details = await getDatabaseBranch(env, options);
1737
+ if (details)
1738
+ return env;
1739
+ console.warn(`Branch ${env} not found in Xata. Ignoring...`);
1740
+ }
1741
+ const gitBranch = await getGitBranch();
1742
+ return resolveXataBranch(gitBranch, options);
1745
1743
  }
1746
1744
  async function getCurrentBranchDetails(options) {
1747
- const env = await getBranchByEnvVariable();
1748
- if (env)
1749
- return getDatabaseBranch(env, options);
1750
- const branch = await getGitBranch();
1751
- if (!branch)
1752
- return getDatabaseBranch(defaultBranch, options);
1753
- const details = await getDatabaseBranch(branch, options);
1754
- if (details)
1755
- return details;
1756
- return getDatabaseBranch(defaultBranch, options);
1745
+ const branch = await getCurrentBranchName(options);
1746
+ return getDatabaseBranch(branch, options);
1747
+ }
1748
+ async function resolveXataBranch(gitBranch, options) {
1749
+ const databaseURL = options?.databaseURL || getDatabaseURL();
1750
+ const apiKey = options?.apiKey || getAPIKey();
1751
+ if (!databaseURL)
1752
+ throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
1753
+ if (!apiKey)
1754
+ throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
1755
+ const [protocol, , host, , dbName] = databaseURL.split("/");
1756
+ const [workspace] = host.split(".");
1757
+ const { branch } = await resolveBranch({
1758
+ apiKey,
1759
+ apiUrl: databaseURL,
1760
+ fetchImpl: getFetchImplementation(options?.fetchImpl),
1761
+ workspacesApiUrl: `${protocol}//${host}`,
1762
+ pathParams: { dbName, workspace },
1763
+ queryParams: { gitBranch, fallbackBranch: getEnvVariable("XATA_FALLBACK_BRANCH") }
1764
+ });
1765
+ return branch;
1757
1766
  }
1758
1767
  async function getDatabaseBranch(branch, options) {
1759
1768
  const databaseURL = options?.databaseURL || getDatabaseURL();
@@ -1842,7 +1851,7 @@ const buildClient = (plugins) => {
1842
1851
  this.db = db;
1843
1852
  this.search = search;
1844
1853
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
1845
- if (!namespace)
1854
+ if (namespace === void 0)
1846
1855
  continue;
1847
1856
  const result = namespace.build(pluginOptions);
1848
1857
  if (result instanceof Promise) {
@@ -1859,7 +1868,7 @@ const buildClient = (plugins) => {
1859
1868
  const databaseURL = options?.databaseURL || getDatabaseURL();
1860
1869
  const apiKey = options?.apiKey || getAPIKey();
1861
1870
  const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
1862
- const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
1871
+ const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
1863
1872
  if (!databaseURL || !apiKey) {
1864
1873
  throw new Error("Options databaseURL and apiKey are required");
1865
1874
  }
@@ -1886,7 +1895,7 @@ const buildClient = (plugins) => {
1886
1895
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
1887
1896
  if (__privateGet(this, _branch))
1888
1897
  return __privateGet(this, _branch);
1889
- if (!param)
1898
+ if (param === void 0)
1890
1899
  return void 0;
1891
1900
  const strategies = Array.isArray(param) ? [...param] : [param];
1892
1901
  const evaluateBranch = async (strategy) => {