@xata.io/client 0.0.0-next.v54eadc62ebcfec4618df94777d47668348ac5b53 → 0.0.0-next.v5bc7e82e3b5ca04db80756931b6ccba0db817c72

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
@@ -37,8 +37,7 @@ function getLens(b64) {
37
37
  throw new Error("Invalid string. Length must be a multiple of 4");
38
38
  }
39
39
  let validLen = b64.indexOf("=");
40
- if (validLen === -1)
41
- validLen = len;
40
+ if (validLen === -1) validLen = len;
42
41
  const placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
43
42
  return [validLen, placeHoldersLen];
44
43
  }
@@ -373,10 +372,8 @@ class Buffer extends Uint8Array {
373
372
  break;
374
373
  }
375
374
  }
376
- if (x < y)
377
- return -1;
378
- if (y < x)
379
- return 1;
375
+ if (x < y) return -1;
376
+ if (y < x) return 1;
380
377
  return 0;
381
378
  }
382
379
  /**
@@ -389,33 +386,21 @@ class Buffer extends Uint8Array {
389
386
  * @param sourceEnd The offset within this buffer at which to end copying (exclusive).
390
387
  */
391
388
  copy(targetBuffer, targetStart, sourceStart, sourceEnd) {
392
- if (!Buffer.isBuffer(targetBuffer))
393
- throw new TypeError("argument should be a Buffer");
394
- if (!sourceStart)
395
- sourceStart = 0;
396
- if (!targetStart)
397
- targetStart = 0;
398
- if (!sourceEnd && sourceEnd !== 0)
399
- sourceEnd = this.length;
400
- if (targetStart >= targetBuffer.length)
401
- targetStart = targetBuffer.length;
402
- if (!targetStart)
403
- targetStart = 0;
404
- if (sourceEnd > 0 && sourceEnd < sourceStart)
405
- sourceEnd = sourceStart;
406
- if (sourceEnd === sourceStart)
407
- return 0;
408
- if (targetBuffer.length === 0 || this.length === 0)
409
- return 0;
389
+ if (!Buffer.isBuffer(targetBuffer)) throw new TypeError("argument should be a Buffer");
390
+ if (!sourceStart) sourceStart = 0;
391
+ if (!targetStart) targetStart = 0;
392
+ if (!sourceEnd && sourceEnd !== 0) sourceEnd = this.length;
393
+ if (targetStart >= targetBuffer.length) targetStart = targetBuffer.length;
394
+ if (!targetStart) targetStart = 0;
395
+ if (sourceEnd > 0 && sourceEnd < sourceStart) sourceEnd = sourceStart;
396
+ if (sourceEnd === sourceStart) return 0;
397
+ if (targetBuffer.length === 0 || this.length === 0) return 0;
410
398
  if (targetStart < 0) {
411
399
  throw new RangeError("targetStart out of bounds");
412
400
  }
413
- if (sourceStart < 0 || sourceStart >= this.length)
414
- throw new RangeError("Index out of range");
415
- if (sourceEnd < 0)
416
- throw new RangeError("sourceEnd out of bounds");
417
- if (sourceEnd > this.length)
418
- sourceEnd = this.length;
401
+ if (sourceStart < 0 || sourceStart >= this.length) throw new RangeError("Index out of range");
402
+ if (sourceEnd < 0) throw new RangeError("sourceEnd out of bounds");
403
+ if (sourceEnd > this.length) sourceEnd = this.length;
419
404
  if (targetBuffer.length - targetStart < sourceEnd - sourceStart) {
420
405
  sourceEnd = targetBuffer.length - targetStart + sourceStart;
421
406
  }
@@ -1576,8 +1561,7 @@ class Buffer extends Uint8Array {
1576
1561
  let c, hi, lo;
1577
1562
  const byteArray = [];
1578
1563
  for (let i = 0; i < str.length; ++i) {
1579
- if ((units -= 2) < 0)
1580
- break;
1564
+ if ((units -= 2) < 0) break;
1581
1565
  c = str.charCodeAt(i);
1582
1566
  hi = c >> 8;
1583
1567
  lo = c % 256;
@@ -1731,13 +1715,10 @@ class Buffer extends Uint8Array {
1731
1715
  let foundIndex = -1;
1732
1716
  for (i = byteOffset; i < arrLength; i++) {
1733
1717
  if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
1734
- if (foundIndex === -1)
1735
- foundIndex = i;
1736
- if (i - foundIndex + 1 === valLength)
1737
- return foundIndex * indexSize;
1718
+ if (foundIndex === -1) foundIndex = i;
1719
+ if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
1738
1720
  } else {
1739
- if (foundIndex !== -1)
1740
- i -= i - foundIndex;
1721
+ if (foundIndex !== -1) i -= i - foundIndex;
1741
1722
  foundIndex = -1;
1742
1723
  }
1743
1724
  }
@@ -1761,18 +1742,13 @@ class Buffer extends Uint8Array {
1761
1742
  return -1;
1762
1743
  }
1763
1744
  static _checkOffset(offset, ext, length) {
1764
- if (offset % 1 !== 0 || offset < 0)
1765
- throw new RangeError("offset is not uint");
1766
- if (offset + ext > length)
1767
- throw new RangeError("Trying to access beyond buffer length");
1745
+ if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint");
1746
+ if (offset + ext > length) throw new RangeError("Trying to access beyond buffer length");
1768
1747
  }
1769
1748
  static _checkInt(buf, value, offset, ext, max, min) {
1770
- if (!Buffer.isBuffer(buf))
1771
- throw new TypeError('"buffer" argument must be a Buffer instance');
1772
- if (value > max || value < min)
1773
- throw new RangeError('"value" argument is out of bounds');
1774
- if (offset + ext > buf.length)
1775
- throw new RangeError("Index out of range");
1749
+ if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
1750
+ if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
1751
+ if (offset + ext > buf.length) throw new RangeError("Index out of range");
1776
1752
  }
1777
1753
  static _getEncoding(encoding) {
1778
1754
  let toLowerCase = false;
@@ -1822,8 +1798,7 @@ const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
1822
1798
  function base64clean(str) {
1823
1799
  str = str.split("=")[0];
1824
1800
  str = str.trim().replace(INVALID_BASE64_RE, "");
1825
- if (str.length < 2)
1826
- return "";
1801
+ if (str.length < 2) return "";
1827
1802
  while (str.length % 4 !== 0) {
1828
1803
  str = str + "=";
1829
1804
  }
@@ -1924,155 +1899,15 @@ function promiseMap(inputValues, mapper) {
1924
1899
  return inputValues.reduce(reducer, Promise.resolve([]));
1925
1900
  }
1926
1901
 
1927
- function getEnvironment() {
1928
- try {
1929
- if (isDefined(process) && isDefined(process.env)) {
1930
- return {
1931
- apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
1932
- databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
1933
- branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
1934
- deployPreview: process.env.XATA_PREVIEW,
1935
- deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
1936
- vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
1937
- vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
1938
- };
1939
- }
1940
- } catch (err) {
1941
- }
1942
- try {
1943
- if (isObject(Deno) && isObject(Deno.env)) {
1944
- return {
1945
- apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
1946
- databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
1947
- branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
1948
- deployPreview: Deno.env.get("XATA_PREVIEW"),
1949
- deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
1950
- vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
1951
- vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
1952
- };
1953
- }
1954
- } catch (err) {
1955
- }
1956
- return {
1957
- apiKey: getGlobalApiKey(),
1958
- databaseURL: getGlobalDatabaseURL(),
1959
- branch: getGlobalBranch(),
1960
- deployPreview: void 0,
1961
- deployPreviewBranch: void 0,
1962
- vercelGitCommitRef: void 0,
1963
- vercelGitRepoOwner: void 0
1964
- };
1965
- }
1966
- function getEnableBrowserVariable() {
1967
- try {
1968
- if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
1969
- return process.env.XATA_ENABLE_BROWSER === "true";
1970
- }
1971
- } catch (err) {
1972
- }
1973
- try {
1974
- if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
1975
- return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
1976
- }
1977
- } catch (err) {
1978
- }
1979
- try {
1980
- return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
1981
- } catch (err) {
1982
- return void 0;
1983
- }
1984
- }
1985
- function getGlobalApiKey() {
1986
- try {
1987
- return XATA_API_KEY;
1988
- } catch (err) {
1989
- return void 0;
1990
- }
1991
- }
1992
- function getGlobalDatabaseURL() {
1993
- try {
1994
- return XATA_DATABASE_URL;
1995
- } catch (err) {
1996
- return void 0;
1997
- }
1998
- }
1999
- function getGlobalBranch() {
2000
- try {
2001
- return XATA_BRANCH;
2002
- } catch (err) {
2003
- return void 0;
2004
- }
2005
- }
2006
- function getDatabaseURL() {
2007
- try {
2008
- const { databaseURL } = getEnvironment();
2009
- return databaseURL;
2010
- } catch (err) {
2011
- return void 0;
2012
- }
2013
- }
2014
- function getAPIKey() {
2015
- try {
2016
- const { apiKey } = getEnvironment();
2017
- return apiKey;
2018
- } catch (err) {
2019
- return void 0;
2020
- }
2021
- }
2022
- function getBranch() {
2023
- try {
2024
- const { branch } = getEnvironment();
2025
- return branch;
2026
- } catch (err) {
2027
- return void 0;
2028
- }
2029
- }
2030
- function buildPreviewBranchName({ org, branch }) {
2031
- return `preview-${org}-${branch}`;
2032
- }
2033
- function getPreviewBranch() {
2034
- try {
2035
- const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
2036
- if (deployPreviewBranch)
2037
- return deployPreviewBranch;
2038
- switch (deployPreview) {
2039
- case "vercel": {
2040
- if (!vercelGitCommitRef || !vercelGitRepoOwner) {
2041
- console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
2042
- return void 0;
2043
- }
2044
- return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
2045
- }
2046
- }
2047
- return void 0;
2048
- } catch (err) {
2049
- return void 0;
2050
- }
2051
- }
2052
-
2053
- var __accessCheck$6 = (obj, member, msg) => {
2054
- if (!member.has(obj))
2055
- throw TypeError("Cannot " + msg);
2056
- };
2057
- var __privateGet$5 = (obj, member, getter) => {
2058
- __accessCheck$6(obj, member, "read from private field");
2059
- return getter ? getter.call(obj) : member.get(obj);
2060
- };
2061
- var __privateAdd$6 = (obj, member, value) => {
2062
- if (member.has(obj))
2063
- throw TypeError("Cannot add the same private member more than once");
2064
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2065
- };
2066
- var __privateSet$4 = (obj, member, value, setter) => {
2067
- __accessCheck$6(obj, member, "write to private field");
2068
- member.set(obj, value);
2069
- return value;
1902
+ var __typeError$6 = (msg) => {
1903
+ throw TypeError(msg);
2070
1904
  };
2071
- var __privateMethod$4 = (obj, member, method) => {
2072
- __accessCheck$6(obj, member, "access private method");
2073
- return method;
2074
- };
2075
- var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
1905
+ var __accessCheck$6 = (obj, member, msg) => member.has(obj) || __typeError$6("Cannot " + msg);
1906
+ var __privateGet$5 = (obj, member, getter) => (__accessCheck$6(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1907
+ var __privateAdd$6 = (obj, member, value) => member.has(obj) ? __typeError$6("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1908
+ var __privateSet$4 = (obj, member, value, setter) => (__accessCheck$6(obj, member, "write to private field"), member.set(obj, value), value);
1909
+ var __privateMethod$4 = (obj, member, method) => (__accessCheck$6(obj, member, "access private method"), method);
1910
+ var _fetch, _queue, _concurrency, _ApiRequestPool_instances, enqueue_fn;
2076
1911
  const REQUEST_TIMEOUT = 5 * 60 * 1e3;
2077
1912
  function getFetchImplementation(userFetch) {
2078
1913
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
@@ -2085,10 +1920,10 @@ function getFetchImplementation(userFetch) {
2085
1920
  }
2086
1921
  class ApiRequestPool {
2087
1922
  constructor(concurrency = 10) {
2088
- __privateAdd$6(this, _enqueue);
2089
- __privateAdd$6(this, _fetch, void 0);
2090
- __privateAdd$6(this, _queue, void 0);
2091
- __privateAdd$6(this, _concurrency, void 0);
1923
+ __privateAdd$6(this, _ApiRequestPool_instances);
1924
+ __privateAdd$6(this, _fetch);
1925
+ __privateAdd$6(this, _queue);
1926
+ __privateAdd$6(this, _concurrency);
2092
1927
  __privateSet$4(this, _queue, []);
2093
1928
  __privateSet$4(this, _concurrency, concurrency);
2094
1929
  this.running = 0;
@@ -2123,7 +1958,7 @@ class ApiRequestPool {
2123
1958
  }
2124
1959
  return response;
2125
1960
  };
2126
- return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
1961
+ return __privateMethod$4(this, _ApiRequestPool_instances, enqueue_fn).call(this, async () => {
2127
1962
  return await runRequest();
2128
1963
  });
2129
1964
  }
@@ -2131,7 +1966,7 @@ class ApiRequestPool {
2131
1966
  _fetch = new WeakMap();
2132
1967
  _queue = new WeakMap();
2133
1968
  _concurrency = new WeakMap();
2134
- _enqueue = new WeakSet();
1969
+ _ApiRequestPool_instances = new WeakSet();
2135
1970
  enqueue_fn = function(task) {
2136
1971
  const promise = new Promise((resolve) => __privateGet$5(this, _queue).push(resolve)).finally(() => {
2137
1972
  this.started--;
@@ -2414,18 +2249,15 @@ function parseProviderString(provider = "production") {
2414
2249
  return provider;
2415
2250
  }
2416
2251
  const [main, workspaces] = provider.split(",");
2417
- if (!main || !workspaces)
2418
- return null;
2252
+ if (!main || !workspaces) return null;
2419
2253
  return { main, workspaces };
2420
2254
  }
2421
2255
  function buildProviderString(provider) {
2422
- if (isHostProviderAlias(provider))
2423
- return provider;
2256
+ if (isHostProviderAlias(provider)) return provider;
2424
2257
  return `${provider.main},${provider.workspaces}`;
2425
2258
  }
2426
2259
  function parseWorkspacesUrlParts(url) {
2427
- if (!isString(url))
2428
- return null;
2260
+ if (!isString(url)) return null;
2429
2261
  const matches = {
2430
2262
  production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh\/db\/([^:]+):?(.*)?/),
2431
2263
  staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev\/db\/([^:]+):?(.*)?/),
@@ -2433,16 +2265,14 @@ function parseWorkspacesUrlParts(url) {
2433
2265
  local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(?:\d+)\/db\/([^:]+):?(.*)?/)
2434
2266
  };
2435
2267
  const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
2436
- if (!isHostProviderAlias(host) || !match)
2437
- return null;
2268
+ if (!isHostProviderAlias(host) || !match) return null;
2438
2269
  return { workspace: match[1], region: match[2], database: match[3], branch: match[4], host };
2439
2270
  }
2440
2271
 
2441
2272
  const pool = new ApiRequestPool();
2442
2273
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
2443
2274
  const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
2444
- if (value === void 0 || value === null)
2445
- return acc;
2275
+ if (value === void 0 || value === null) return acc;
2446
2276
  return { ...acc, [key]: value };
2447
2277
  }, {});
2448
2278
  const query = new URLSearchParams(cleanQueryParams).toString();
@@ -2490,8 +2320,7 @@ function hostHeader(url) {
2490
2320
  return groups?.host ? { Host: groups.host } : {};
2491
2321
  }
2492
2322
  async function parseBody(body, headers) {
2493
- if (!isDefined(body))
2494
- return void 0;
2323
+ if (!isDefined(body)) return void 0;
2495
2324
  if (isBlob(body) || typeof body.text === "function") {
2496
2325
  return body;
2497
2326
  }
@@ -2570,8 +2399,7 @@ async function fetch$1({
2570
2399
  [TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
2571
2400
  });
2572
2401
  const message = response.headers?.get("x-xata-message");
2573
- if (message)
2574
- console.warn(message);
2402
+ if (message) console.warn(message);
2575
2403
  if (response.status === 204) {
2576
2404
  return {};
2577
2405
  }
@@ -2661,6 +2489,24 @@ const applyMigration = (variables, signal) => dataPlaneFetch({
2661
2489
  ...variables,
2662
2490
  signal
2663
2491
  });
2492
+ const startMigration = (variables, signal) => dataPlaneFetch({
2493
+ url: "/db/{dbBranchName}/migrations/start",
2494
+ method: "post",
2495
+ ...variables,
2496
+ signal
2497
+ });
2498
+ const completeMigration = (variables, signal) => dataPlaneFetch({
2499
+ url: "/db/{dbBranchName}/migrations/complete",
2500
+ method: "post",
2501
+ ...variables,
2502
+ signal
2503
+ });
2504
+ const rollbackMigration = (variables, signal) => dataPlaneFetch({
2505
+ url: "/db/{dbBranchName}/migrations/rollback",
2506
+ method: "post",
2507
+ ...variables,
2508
+ signal
2509
+ });
2664
2510
  const adaptTable = (variables, signal) => dataPlaneFetch({
2665
2511
  url: "/db/{dbBranchName}/migrations/adapt/{tableName}",
2666
2512
  method: "post",
@@ -3076,9 +2922,18 @@ const sqlQuery = (variables, signal) => dataPlaneFetch({
3076
2922
  ...variables,
3077
2923
  signal
3078
2924
  });
2925
+ const sqlBatchQuery = (variables, signal) => dataPlaneFetch({
2926
+ url: "/db/{dbBranchName}/sql/batch",
2927
+ method: "post",
2928
+ ...variables,
2929
+ signal
2930
+ });
3079
2931
  const operationsByTag$2 = {
3080
2932
  migrations: {
3081
2933
  applyMigration,
2934
+ startMigration,
2935
+ completeMigration,
2936
+ rollbackMigration,
3082
2937
  adaptTable,
3083
2938
  adaptAllTables,
3084
2939
  getBranchMigrationJobStatus,
@@ -3163,7 +3018,7 @@ const operationsByTag$2 = {
3163
3018
  summarizeTable,
3164
3019
  aggregateTable
3165
3020
  },
3166
- sql: { sqlQuery }
3021
+ sql: { sqlQuery, sqlBatchQuery }
3167
3022
  };
3168
3023
 
3169
3024
  const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
@@ -3473,7 +3328,7 @@ const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
3473
3328
  const buildApiClient = () => class {
3474
3329
  constructor(options = {}) {
3475
3330
  const provider = options.host ?? "production";
3476
- const apiKey = options.apiKey ?? getAPIKey();
3331
+ const apiKey = options.apiKey;
3477
3332
  const trace = options.trace ?? defaultTrace;
3478
3333
  const clientID = generateUUID();
3479
3334
  if (!apiKey) {
@@ -3540,8 +3395,7 @@ function buildTransformString(transformations) {
3540
3395
  ).join(",");
3541
3396
  }
3542
3397
  function transformImage(url, ...transformations) {
3543
- if (!isDefined(url))
3544
- return void 0;
3398
+ if (!isDefined(url)) return void 0;
3545
3399
  const newTransformations = buildTransformString(transformations);
3546
3400
  const { hostname, pathname, search } = new URL(url);
3547
3401
  const pathParts = pathname.split("/");
@@ -3654,8 +3508,7 @@ class XataFile {
3654
3508
  }
3655
3509
  }
3656
3510
  const parseInputFileEntry = async (entry) => {
3657
- if (!isDefined(entry))
3658
- return null;
3511
+ if (!isDefined(entry)) return null;
3659
3512
  const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
3660
3513
  return compactObject({
3661
3514
  id,
@@ -3670,24 +3523,19 @@ const parseInputFileEntry = async (entry) => {
3670
3523
  };
3671
3524
 
3672
3525
  function cleanFilter(filter) {
3673
- if (!isDefined(filter))
3674
- return void 0;
3675
- if (!isObject(filter))
3676
- return filter;
3526
+ if (!isDefined(filter)) return void 0;
3527
+ if (!isObject(filter)) return filter;
3677
3528
  const values = Object.fromEntries(
3678
3529
  Object.entries(filter).reduce((acc, [key, value]) => {
3679
- if (!isDefined(value))
3680
- return acc;
3530
+ if (!isDefined(value)) return acc;
3681
3531
  if (Array.isArray(value)) {
3682
3532
  const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
3683
- if (clean.length === 0)
3684
- return acc;
3533
+ if (clean.length === 0) return acc;
3685
3534
  return [...acc, [key, clean]];
3686
3535
  }
3687
3536
  if (isObject(value)) {
3688
3537
  const clean = cleanFilter(value);
3689
- if (!isDefined(clean))
3690
- return acc;
3538
+ if (!isDefined(clean)) return acc;
3691
3539
  return [...acc, [key, clean]];
3692
3540
  }
3693
3541
  return [...acc, [key, value]];
@@ -3697,10 +3545,8 @@ function cleanFilter(filter) {
3697
3545
  }
3698
3546
 
3699
3547
  function stringifyJson(value) {
3700
- if (!isDefined(value))
3701
- return value;
3702
- if (isString(value))
3703
- return value;
3548
+ if (!isDefined(value)) return value;
3549
+ if (isString(value)) return value;
3704
3550
  try {
3705
3551
  return JSON.stringify(value);
3706
3552
  } catch (e) {
@@ -3715,28 +3561,17 @@ function parseJson(value) {
3715
3561
  }
3716
3562
  }
3717
3563
 
3718
- var __accessCheck$5 = (obj, member, msg) => {
3719
- if (!member.has(obj))
3720
- throw TypeError("Cannot " + msg);
3721
- };
3722
- var __privateGet$4 = (obj, member, getter) => {
3723
- __accessCheck$5(obj, member, "read from private field");
3724
- return getter ? getter.call(obj) : member.get(obj);
3725
- };
3726
- var __privateAdd$5 = (obj, member, value) => {
3727
- if (member.has(obj))
3728
- throw TypeError("Cannot add the same private member more than once");
3729
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3730
- };
3731
- var __privateSet$3 = (obj, member, value, setter) => {
3732
- __accessCheck$5(obj, member, "write to private field");
3733
- member.set(obj, value);
3734
- return value;
3564
+ var __typeError$5 = (msg) => {
3565
+ throw TypeError(msg);
3735
3566
  };
3567
+ var __accessCheck$5 = (obj, member, msg) => member.has(obj) || __typeError$5("Cannot " + msg);
3568
+ var __privateGet$4 = (obj, member, getter) => (__accessCheck$5(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
3569
+ var __privateAdd$5 = (obj, member, value) => member.has(obj) ? __typeError$5("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3570
+ var __privateSet$3 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value);
3736
3571
  var _query, _page;
3737
3572
  class Page {
3738
3573
  constructor(query, meta, records = []) {
3739
- __privateAdd$5(this, _query, void 0);
3574
+ __privateAdd$5(this, _query);
3740
3575
  __privateSet$3(this, _query, query);
3741
3576
  this.meta = meta;
3742
3577
  this.records = new PageRecordArray(this, records);
@@ -3823,7 +3658,7 @@ class RecordArray extends Array {
3823
3658
  const _PageRecordArray = class _PageRecordArray extends Array {
3824
3659
  constructor(...args) {
3825
3660
  super(..._PageRecordArray.parseConstructorParams(...args));
3826
- __privateAdd$5(this, _page, void 0);
3661
+ __privateAdd$5(this, _page);
3827
3662
  __privateSet$3(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
3828
3663
  }
3829
3664
  static parseConstructorParams(...args) {
@@ -3894,34 +3729,20 @@ const _PageRecordArray = class _PageRecordArray extends Array {
3894
3729
  _page = new WeakMap();
3895
3730
  let PageRecordArray = _PageRecordArray;
3896
3731
 
3897
- var __accessCheck$4 = (obj, member, msg) => {
3898
- if (!member.has(obj))
3899
- throw TypeError("Cannot " + msg);
3900
- };
3901
- var __privateGet$3 = (obj, member, getter) => {
3902
- __accessCheck$4(obj, member, "read from private field");
3903
- return getter ? getter.call(obj) : member.get(obj);
3904
- };
3905
- var __privateAdd$4 = (obj, member, value) => {
3906
- if (member.has(obj))
3907
- throw TypeError("Cannot add the same private member more than once");
3908
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3732
+ var __typeError$4 = (msg) => {
3733
+ throw TypeError(msg);
3909
3734
  };
3910
- var __privateSet$2 = (obj, member, value, setter) => {
3911
- __accessCheck$4(obj, member, "write to private field");
3912
- member.set(obj, value);
3913
- return value;
3914
- };
3915
- var __privateMethod$3 = (obj, member, method) => {
3916
- __accessCheck$4(obj, member, "access private method");
3917
- return method;
3918
- };
3919
- var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
3735
+ var __accessCheck$4 = (obj, member, msg) => member.has(obj) || __typeError$4("Cannot " + msg);
3736
+ var __privateGet$3 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
3737
+ var __privateAdd$4 = (obj, member, value) => member.has(obj) ? __typeError$4("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3738
+ var __privateSet$2 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value);
3739
+ var __privateMethod$3 = (obj, member, method) => (__accessCheck$4(obj, member, "access private method"), method);
3740
+ var _table$1, _repository, _data, _Query_instances, cleanFilterConstraint_fn;
3920
3741
  const _Query = class _Query {
3921
3742
  constructor(repository, table, data, rawParent) {
3922
- __privateAdd$4(this, _cleanFilterConstraint);
3923
- __privateAdd$4(this, _table$1, void 0);
3924
- __privateAdd$4(this, _repository, void 0);
3743
+ __privateAdd$4(this, _Query_instances);
3744
+ __privateAdd$4(this, _table$1);
3745
+ __privateAdd$4(this, _repository);
3925
3746
  __privateAdd$4(this, _data, { filter: {} });
3926
3747
  // Implements pagination
3927
3748
  this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
@@ -3999,12 +3820,12 @@ const _Query = class _Query {
3999
3820
  filter(a, b) {
4000
3821
  if (arguments.length === 1) {
4001
3822
  const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
4002
- [column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
3823
+ [column]: __privateMethod$3(this, _Query_instances, cleanFilterConstraint_fn).call(this, column, constraint)
4003
3824
  }));
4004
3825
  const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat(constraints));
4005
3826
  return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
4006
3827
  } else {
4007
- const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
3828
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _Query_instances, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
4008
3829
  const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat(constraints));
4009
3830
  return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
4010
3831
  }
@@ -4083,8 +3904,7 @@ const _Query = class _Query {
4083
3904
  }
4084
3905
  async getFirstOrThrow(options = {}) {
4085
3906
  const records = await this.getMany({ ...options, pagination: { size: 1 } });
4086
- if (records[0] === void 0)
4087
- throw new Error("No results found.");
3907
+ if (records[0] === void 0) throw new Error("No results found.");
4088
3908
  return records[0];
4089
3909
  }
4090
3910
  async summarize(params = {}) {
@@ -4139,7 +3959,7 @@ const _Query = class _Query {
4139
3959
  _table$1 = new WeakMap();
4140
3960
  _repository = new WeakMap();
4141
3961
  _data = new WeakMap();
4142
- _cleanFilterConstraint = new WeakSet();
3962
+ _Query_instances = new WeakSet();
4143
3963
  cleanFilterConstraint_fn = function(column, value) {
4144
3964
  const columnType = __privateGet$3(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
4145
3965
  if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
@@ -4200,8 +4020,7 @@ function isSortFilterString(value) {
4200
4020
  }
4201
4021
  function isSortFilterBase(filter) {
4202
4022
  return isObject(filter) && Object.entries(filter).every(([key, value]) => {
4203
- if (key === "*")
4204
- return value === "random";
4023
+ if (key === "*") return value === "random";
4205
4024
  return value === "asc" || value === "desc";
4206
4025
  });
4207
4026
  }
@@ -4222,29 +4041,15 @@ function buildSortFilter(filter) {
4222
4041
  }
4223
4042
  }
4224
4043
 
4225
- var __accessCheck$3 = (obj, member, msg) => {
4226
- if (!member.has(obj))
4227
- throw TypeError("Cannot " + msg);
4228
- };
4229
- var __privateGet$2 = (obj, member, getter) => {
4230
- __accessCheck$3(obj, member, "read from private field");
4231
- return getter ? getter.call(obj) : member.get(obj);
4232
- };
4233
- var __privateAdd$3 = (obj, member, value) => {
4234
- if (member.has(obj))
4235
- throw TypeError("Cannot add the same private member more than once");
4236
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
4044
+ var __typeError$3 = (msg) => {
4045
+ throw TypeError(msg);
4237
4046
  };
4238
- var __privateSet$1 = (obj, member, value, setter) => {
4239
- __accessCheck$3(obj, member, "write to private field");
4240
- member.set(obj, value);
4241
- return value;
4242
- };
4243
- var __privateMethod$2 = (obj, member, method) => {
4244
- __accessCheck$3(obj, member, "access private method");
4245
- return method;
4246
- };
4247
- var _table, _getFetchProps, _db, _schemaTables, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _getSchemaTables, getSchemaTables_fn, _transformObjectToApi, transformObjectToApi_fn;
4047
+ var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
4048
+ var __privateGet$2 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
4049
+ var __privateAdd$3 = (obj, member, value) => member.has(obj) ? __typeError$3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
4050
+ var __privateSet$1 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value);
4051
+ var __privateMethod$2 = (obj, member, method) => (__accessCheck$3(obj, member, "access private method"), method);
4052
+ var _table, _getFetchProps, _db, _schemaTables, _trace, _RestRepository_instances, insertRecordWithoutId_fn, insertRecordWithId_fn, insertRecords_fn, updateRecordWithID_fn, updateRecords_fn, upsertRecordWithID_fn, deleteRecord_fn, deleteRecords_fn, getSchemaTables_fn, transformObjectToApi_fn;
4248
4053
  const BULK_OPERATION_MAX_SIZE = 1e3;
4249
4054
  class Repository extends Query {
4250
4055
  }
@@ -4255,21 +4060,12 @@ class RestRepository extends Query {
4255
4060
  { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
4256
4061
  {}
4257
4062
  );
4258
- __privateAdd$3(this, _insertRecordWithoutId);
4259
- __privateAdd$3(this, _insertRecordWithId);
4260
- __privateAdd$3(this, _insertRecords);
4261
- __privateAdd$3(this, _updateRecordWithID);
4262
- __privateAdd$3(this, _updateRecords);
4263
- __privateAdd$3(this, _upsertRecordWithID);
4264
- __privateAdd$3(this, _deleteRecord);
4265
- __privateAdd$3(this, _deleteRecords);
4266
- __privateAdd$3(this, _getSchemaTables);
4267
- __privateAdd$3(this, _transformObjectToApi);
4268
- __privateAdd$3(this, _table, void 0);
4269
- __privateAdd$3(this, _getFetchProps, void 0);
4270
- __privateAdd$3(this, _db, void 0);
4271
- __privateAdd$3(this, _schemaTables, void 0);
4272
- __privateAdd$3(this, _trace, void 0);
4063
+ __privateAdd$3(this, _RestRepository_instances);
4064
+ __privateAdd$3(this, _table);
4065
+ __privateAdd$3(this, _getFetchProps);
4066
+ __privateAdd$3(this, _db);
4067
+ __privateAdd$3(this, _schemaTables);
4068
+ __privateAdd$3(this, _trace);
4273
4069
  __privateSet$1(this, _table, options.table);
4274
4070
  __privateSet$1(this, _db, options.db);
4275
4071
  __privateSet$1(this, _schemaTables, options.schemaTables);
@@ -4288,31 +4084,28 @@ class RestRepository extends Query {
4288
4084
  return __privateGet$2(this, _trace).call(this, "create", async () => {
4289
4085
  const ifVersion = parseIfVersion(b, c, d);
4290
4086
  if (Array.isArray(a)) {
4291
- if (a.length === 0)
4292
- return [];
4293
- const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
4087
+ if (a.length === 0) return [];
4088
+ const ids = await __privateMethod$2(this, _RestRepository_instances, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
4294
4089
  const columns = isValidSelectableColumns(b) ? b : ["*"];
4295
4090
  const result = await this.read(ids, columns);
4296
4091
  return result;
4297
4092
  }
4298
4093
  if (isString(a) && isObject(b)) {
4299
- if (a === "")
4300
- throw new Error("The id can't be empty");
4094
+ if (a === "") throw new Error("The id can't be empty");
4301
4095
  const columns = isValidSelectableColumns(c) ? c : void 0;
4302
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
4096
+ return await __privateMethod$2(this, _RestRepository_instances, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
4303
4097
  }
4304
4098
  if (isObject(a) && isString(a.xata_id)) {
4305
- if (a.xata_id === "")
4306
- throw new Error("The id can't be empty");
4099
+ if (a.xata_id === "") throw new Error("The id can't be empty");
4307
4100
  const columns = isValidSelectableColumns(b) ? b : void 0;
4308
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
4101
+ return await __privateMethod$2(this, _RestRepository_instances, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
4309
4102
  createOnly: true,
4310
4103
  ifVersion
4311
4104
  });
4312
4105
  }
4313
4106
  if (isObject(a)) {
4314
4107
  const columns = isValidSelectableColumns(b) ? b : void 0;
4315
- return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
4108
+ return __privateMethod$2(this, _RestRepository_instances, insertRecordWithoutId_fn).call(this, a, columns);
4316
4109
  }
4317
4110
  throw new Error("Invalid arguments for create method");
4318
4111
  });
@@ -4321,8 +4114,7 @@ class RestRepository extends Query {
4321
4114
  return __privateGet$2(this, _trace).call(this, "read", async () => {
4322
4115
  const columns = isValidSelectableColumns(b) ? b : ["*"];
4323
4116
  if (Array.isArray(a)) {
4324
- if (a.length === 0)
4325
- return [];
4117
+ if (a.length === 0) return [];
4326
4118
  const ids = a.map((item) => extractId(item));
4327
4119
  const finalObjects = await this.getAll({ filter: { xata_id: { $any: compact(ids) } }, columns });
4328
4120
  const dictionary = finalObjects.reduce((acc, object) => {
@@ -4345,7 +4137,7 @@ class RestRepository extends Query {
4345
4137
  queryParams: { columns },
4346
4138
  ...__privateGet$2(this, _getFetchProps).call(this)
4347
4139
  });
4348
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4140
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4349
4141
  return initObject(
4350
4142
  __privateGet$2(this, _db),
4351
4143
  schemaTables,
@@ -4386,11 +4178,10 @@ class RestRepository extends Query {
4386
4178
  return __privateGet$2(this, _trace).call(this, "update", async () => {
4387
4179
  const ifVersion = parseIfVersion(b, c, d);
4388
4180
  if (Array.isArray(a)) {
4389
- if (a.length === 0)
4390
- return [];
4181
+ if (a.length === 0) return [];
4391
4182
  const existing = await this.read(a, ["xata_id"]);
4392
4183
  const updates = a.filter((_item, index) => existing[index] !== null);
4393
- await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
4184
+ await __privateMethod$2(this, _RestRepository_instances, updateRecords_fn).call(this, updates, {
4394
4185
  ifVersion,
4395
4186
  upsert: false
4396
4187
  });
@@ -4401,15 +4192,14 @@ class RestRepository extends Query {
4401
4192
  try {
4402
4193
  if (isString(a) && isObject(b)) {
4403
4194
  const columns = isValidSelectableColumns(c) ? c : void 0;
4404
- return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
4195
+ return await __privateMethod$2(this, _RestRepository_instances, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
4405
4196
  }
4406
4197
  if (isObject(a) && isString(a.xata_id)) {
4407
4198
  const columns = isValidSelectableColumns(b) ? b : void 0;
4408
- return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
4199
+ return await __privateMethod$2(this, _RestRepository_instances, updateRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
4409
4200
  }
4410
4201
  } catch (error) {
4411
- if (error.status === 422)
4412
- return null;
4202
+ if (error.status === 422) return null;
4413
4203
  throw error;
4414
4204
  }
4415
4205
  throw new Error("Invalid arguments for update method");
@@ -4438,9 +4228,8 @@ class RestRepository extends Query {
4438
4228
  return __privateGet$2(this, _trace).call(this, "createOrUpdate", async () => {
4439
4229
  const ifVersion = parseIfVersion(b, c, d);
4440
4230
  if (Array.isArray(a)) {
4441
- if (a.length === 0)
4442
- return [];
4443
- await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
4231
+ if (a.length === 0) return [];
4232
+ await __privateMethod$2(this, _RestRepository_instances, updateRecords_fn).call(this, a, {
4444
4233
  ifVersion,
4445
4234
  upsert: true
4446
4235
  });
@@ -4449,16 +4238,14 @@ class RestRepository extends Query {
4449
4238
  return result;
4450
4239
  }
4451
4240
  if (isString(a) && isObject(b)) {
4452
- if (a === "")
4453
- throw new Error("The id can't be empty");
4241
+ if (a === "") throw new Error("The id can't be empty");
4454
4242
  const columns = isValidSelectableColumns(c) ? c : void 0;
4455
- return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
4243
+ return await __privateMethod$2(this, _RestRepository_instances, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
4456
4244
  }
4457
4245
  if (isObject(a) && isString(a.xata_id)) {
4458
- if (a.xata_id === "")
4459
- throw new Error("The id can't be empty");
4246
+ if (a.xata_id === "") throw new Error("The id can't be empty");
4460
4247
  const columns = isValidSelectableColumns(c) ? c : void 0;
4461
- return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
4248
+ return await __privateMethod$2(this, _RestRepository_instances, upsertRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
4462
4249
  }
4463
4250
  if (!isDefined(a) && isObject(b)) {
4464
4251
  return await this.create(b, c);
@@ -4473,24 +4260,21 @@ class RestRepository extends Query {
4473
4260
  return __privateGet$2(this, _trace).call(this, "createOrReplace", async () => {
4474
4261
  const ifVersion = parseIfVersion(b, c, d);
4475
4262
  if (Array.isArray(a)) {
4476
- if (a.length === 0)
4477
- return [];
4478
- const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
4263
+ if (a.length === 0) return [];
4264
+ const ids = await __privateMethod$2(this, _RestRepository_instances, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
4479
4265
  const columns = isValidSelectableColumns(b) ? b : ["*"];
4480
4266
  const result = await this.read(ids, columns);
4481
4267
  return result;
4482
4268
  }
4483
4269
  if (isString(a) && isObject(b)) {
4484
- if (a === "")
4485
- throw new Error("The id can't be empty");
4270
+ if (a === "") throw new Error("The id can't be empty");
4486
4271
  const columns = isValidSelectableColumns(c) ? c : void 0;
4487
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
4272
+ return await __privateMethod$2(this, _RestRepository_instances, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
4488
4273
  }
4489
4274
  if (isObject(a) && isString(a.xata_id)) {
4490
- if (a.xata_id === "")
4491
- throw new Error("The id can't be empty");
4275
+ if (a.xata_id === "") throw new Error("The id can't be empty");
4492
4276
  const columns = isValidSelectableColumns(c) ? c : void 0;
4493
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
4277
+ return await __privateMethod$2(this, _RestRepository_instances, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
4494
4278
  createOnly: false,
4495
4279
  ifVersion
4496
4280
  });
@@ -4507,25 +4291,22 @@ class RestRepository extends Query {
4507
4291
  async delete(a, b) {
4508
4292
  return __privateGet$2(this, _trace).call(this, "delete", async () => {
4509
4293
  if (Array.isArray(a)) {
4510
- if (a.length === 0)
4511
- return [];
4294
+ if (a.length === 0) return [];
4512
4295
  const ids = a.map((o) => {
4513
- if (isString(o))
4514
- return o;
4515
- if (isString(o.xata_id))
4516
- return o.xata_id;
4296
+ if (isString(o)) return o;
4297
+ if (isString(o.xata_id)) return o.xata_id;
4517
4298
  throw new Error("Invalid arguments for delete method");
4518
4299
  });
4519
4300
  const columns = isValidSelectableColumns(b) ? b : ["*"];
4520
4301
  const result = await this.read(a, columns);
4521
- await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
4302
+ await __privateMethod$2(this, _RestRepository_instances, deleteRecords_fn).call(this, ids);
4522
4303
  return result;
4523
4304
  }
4524
4305
  if (isString(a)) {
4525
- return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
4306
+ return __privateMethod$2(this, _RestRepository_instances, deleteRecord_fn).call(this, a, b);
4526
4307
  }
4527
4308
  if (isObject(a) && isString(a.xata_id)) {
4528
- return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.xata_id, b);
4309
+ return __privateMethod$2(this, _RestRepository_instances, deleteRecord_fn).call(this, a.xata_id, b);
4529
4310
  }
4530
4311
  throw new Error("Invalid arguments for delete method");
4531
4312
  });
@@ -4569,7 +4350,7 @@ class RestRepository extends Query {
4569
4350
  },
4570
4351
  ...__privateGet$2(this, _getFetchProps).call(this)
4571
4352
  });
4572
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4353
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4573
4354
  return {
4574
4355
  records: records.map((item) => initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), item, ["*"])),
4575
4356
  totalCount
@@ -4594,7 +4375,7 @@ class RestRepository extends Query {
4594
4375
  },
4595
4376
  ...__privateGet$2(this, _getFetchProps).call(this)
4596
4377
  });
4597
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4378
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4598
4379
  return {
4599
4380
  records: records.map((item) => initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), item, ["*"])),
4600
4381
  totalCount
@@ -4636,7 +4417,7 @@ class RestRepository extends Query {
4636
4417
  fetchOptions: data.fetchOptions,
4637
4418
  ...__privateGet$2(this, _getFetchProps).call(this)
4638
4419
  });
4639
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4420
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4640
4421
  const records = objects.map(
4641
4422
  (record) => initObject(
4642
4423
  __privateGet$2(this, _db),
@@ -4670,7 +4451,7 @@ class RestRepository extends Query {
4670
4451
  },
4671
4452
  ...__privateGet$2(this, _getFetchProps).call(this)
4672
4453
  });
4673
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4454
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4674
4455
  return {
4675
4456
  ...result,
4676
4457
  summaries: result.summaries.map(
@@ -4718,9 +4499,9 @@ _getFetchProps = new WeakMap();
4718
4499
  _db = new WeakMap();
4719
4500
  _schemaTables = new WeakMap();
4720
4501
  _trace = new WeakMap();
4721
- _insertRecordWithoutId = new WeakSet();
4502
+ _RestRepository_instances = new WeakSet();
4722
4503
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
4723
- const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
4504
+ const record = await __privateMethod$2(this, _RestRepository_instances, transformObjectToApi_fn).call(this, object);
4724
4505
  const response = await insertRecord({
4725
4506
  pathParams: {
4726
4507
  workspace: "{workspaceId}",
@@ -4732,14 +4513,12 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
4732
4513
  body: record,
4733
4514
  ...__privateGet$2(this, _getFetchProps).call(this)
4734
4515
  });
4735
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4516
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4736
4517
  return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
4737
4518
  };
4738
- _insertRecordWithId = new WeakSet();
4739
4519
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
4740
- if (!recordId)
4741
- return null;
4742
- const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
4520
+ if (!recordId) return null;
4521
+ const record = await __privateMethod$2(this, _RestRepository_instances, transformObjectToApi_fn).call(this, object);
4743
4522
  const response = await insertRecordWithID({
4744
4523
  pathParams: {
4745
4524
  workspace: "{workspaceId}",
@@ -4752,13 +4531,12 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
4752
4531
  queryParams: { createOnly, columns, ifVersion },
4753
4532
  ...__privateGet$2(this, _getFetchProps).call(this)
4754
4533
  });
4755
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4534
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4756
4535
  return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
4757
4536
  };
4758
- _insertRecords = new WeakSet();
4759
4537
  insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
4760
4538
  const operations = await promiseMap(objects, async (object) => {
4761
- const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
4539
+ const record = await __privateMethod$2(this, _RestRepository_instances, transformObjectToApi_fn).call(this, object);
4762
4540
  return { insert: { table: __privateGet$2(this, _table), record, createOnly, ifVersion } };
4763
4541
  });
4764
4542
  const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
@@ -4783,11 +4561,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
4783
4561
  }
4784
4562
  return ids;
4785
4563
  };
4786
- _updateRecordWithID = new WeakSet();
4787
4564
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
4788
- if (!recordId)
4789
- return null;
4790
- const { xata_id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
4565
+ if (!recordId) return null;
4566
+ const { xata_id: _id, ...record } = await __privateMethod$2(this, _RestRepository_instances, transformObjectToApi_fn).call(this, object);
4791
4567
  try {
4792
4568
  const response = await updateRecordWithID({
4793
4569
  pathParams: {
@@ -4801,7 +4577,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
4801
4577
  body: record,
4802
4578
  ...__privateGet$2(this, _getFetchProps).call(this)
4803
4579
  });
4804
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4580
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4805
4581
  return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
4806
4582
  } catch (e) {
4807
4583
  if (isObject(e) && e.status === 404) {
@@ -4810,10 +4586,9 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
4810
4586
  throw e;
4811
4587
  }
4812
4588
  };
4813
- _updateRecords = new WeakSet();
4814
4589
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
4815
4590
  const operations = await promiseMap(objects, async ({ xata_id, ...object }) => {
4816
- const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
4591
+ const fields = await __privateMethod$2(this, _RestRepository_instances, transformObjectToApi_fn).call(this, object);
4817
4592
  return { update: { table: __privateGet$2(this, _table), id: xata_id, ifVersion, upsert, fields } };
4818
4593
  });
4819
4594
  const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
@@ -4838,10 +4613,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
4838
4613
  }
4839
4614
  return ids;
4840
4615
  };
4841
- _upsertRecordWithID = new WeakSet();
4842
4616
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
4843
- if (!recordId)
4844
- return null;
4617
+ if (!recordId) return null;
4845
4618
  const response = await upsertRecordWithID({
4846
4619
  pathParams: {
4847
4620
  workspace: "{workspaceId}",
@@ -4854,13 +4627,11 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
4854
4627
  body: object,
4855
4628
  ...__privateGet$2(this, _getFetchProps).call(this)
4856
4629
  });
4857
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4630
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4858
4631
  return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
4859
4632
  };
4860
- _deleteRecord = new WeakSet();
4861
4633
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
4862
- if (!recordId)
4863
- return null;
4634
+ if (!recordId) return null;
4864
4635
  try {
4865
4636
  const response = await deleteRecord({
4866
4637
  pathParams: {
@@ -4873,7 +4644,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
4873
4644
  queryParams: { columns },
4874
4645
  ...__privateGet$2(this, _getFetchProps).call(this)
4875
4646
  });
4876
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4647
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4877
4648
  return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
4878
4649
  } catch (e) {
4879
4650
  if (isObject(e) && e.status === 404) {
@@ -4882,7 +4653,6 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
4882
4653
  throw e;
4883
4654
  }
4884
4655
  };
4885
- _deleteRecords = new WeakSet();
4886
4656
  deleteRecords_fn = async function(recordIds) {
4887
4657
  const chunkedOperations = chunk(
4888
4658
  compact(recordIds).map((id) => ({ delete: { table: __privateGet$2(this, _table), id } })),
@@ -4900,10 +4670,8 @@ deleteRecords_fn = async function(recordIds) {
4900
4670
  });
4901
4671
  }
4902
4672
  };
4903
- _getSchemaTables = new WeakSet();
4904
4673
  getSchemaTables_fn = async function() {
4905
- if (__privateGet$2(this, _schemaTables))
4906
- return __privateGet$2(this, _schemaTables);
4674
+ if (__privateGet$2(this, _schemaTables)) return __privateGet$2(this, _schemaTables);
4907
4675
  const { schema } = await getBranchDetails({
4908
4676
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
4909
4677
  ...__privateGet$2(this, _getFetchProps).call(this)
@@ -4911,16 +4679,13 @@ getSchemaTables_fn = async function() {
4911
4679
  __privateSet$1(this, _schemaTables, schema.tables);
4912
4680
  return schema.tables;
4913
4681
  };
4914
- _transformObjectToApi = new WeakSet();
4915
4682
  transformObjectToApi_fn = async function(object) {
4916
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4683
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4917
4684
  const schema = schemaTables.find((table) => table.name === __privateGet$2(this, _table));
4918
- if (!schema)
4919
- throw new Error(`Table ${__privateGet$2(this, _table)} not found in schema`);
4685
+ if (!schema) throw new Error(`Table ${__privateGet$2(this, _table)} not found in schema`);
4920
4686
  const result = {};
4921
4687
  for (const [key, value] of Object.entries(object)) {
4922
- if (["xata_version", "xata_createdat", "xata_updatedat"].includes(key))
4923
- continue;
4688
+ if (["xata_version", "xata_createdat", "xata_updatedat"].includes(key)) continue;
4924
4689
  const type = schema.columns.find((column) => column.name === key)?.type;
4925
4690
  switch (type) {
4926
4691
  case "link": {
@@ -4950,11 +4715,9 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
4950
4715
  const data = {};
4951
4716
  Object.assign(data, { ...object });
4952
4717
  const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
4953
- if (!columns)
4954
- console.error(`Table ${table} not found in schema`);
4718
+ if (!columns) console.error(`Table ${table} not found in schema`);
4955
4719
  for (const column of columns ?? []) {
4956
- if (!isValidColumn(selectedColumns, column))
4957
- continue;
4720
+ if (!isValidColumn(selectedColumns, column)) continue;
4958
4721
  const value = data[column.name];
4959
4722
  switch (column.type) {
4960
4723
  case "datetime": {
@@ -5040,15 +4803,12 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
5040
4803
  return record;
5041
4804
  };
5042
4805
  function extractId(value) {
5043
- if (isString(value))
5044
- return value;
5045
- if (isObject(value) && isString(value.xata_id))
5046
- return value.xata_id;
4806
+ if (isString(value)) return value;
4807
+ if (isObject(value) && isString(value.xata_id)) return value.xata_id;
5047
4808
  return void 0;
5048
4809
  }
5049
4810
  function isValidColumn(columns, column) {
5050
- if (columns.includes("*"))
5051
- return true;
4811
+ if (columns.includes("*")) return true;
5052
4812
  return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
5053
4813
  }
5054
4814
  function parseIfVersion(...args) {
@@ -5088,19 +4848,12 @@ const includesAll = (value) => ({ $includesAll: value });
5088
4848
  const includesNone = (value) => ({ $includesNone: value });
5089
4849
  const includesAny = (value) => ({ $includesAny: value });
5090
4850
 
5091
- var __accessCheck$2 = (obj, member, msg) => {
5092
- if (!member.has(obj))
5093
- throw TypeError("Cannot " + msg);
5094
- };
5095
- var __privateGet$1 = (obj, member, getter) => {
5096
- __accessCheck$2(obj, member, "read from private field");
5097
- return getter ? getter.call(obj) : member.get(obj);
5098
- };
5099
- var __privateAdd$2 = (obj, member, value) => {
5100
- if (member.has(obj))
5101
- throw TypeError("Cannot add the same private member more than once");
5102
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
4851
+ var __typeError$2 = (msg) => {
4852
+ throw TypeError(msg);
5103
4853
  };
4854
+ var __accessCheck$2 = (obj, member, msg) => member.has(obj) || __typeError$2("Cannot " + msg);
4855
+ var __privateGet$1 = (obj, member, getter) => (__accessCheck$2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
4856
+ var __privateAdd$2 = (obj, member, value) => member.has(obj) ? __typeError$2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
5104
4857
  var _tables;
5105
4858
  class SchemaPlugin extends XataPlugin {
5106
4859
  constructor() {
@@ -5112,8 +4865,7 @@ class SchemaPlugin extends XataPlugin {
5112
4865
  {},
5113
4866
  {
5114
4867
  get: (_target, table) => {
5115
- if (!isString(table))
5116
- throw new Error("Invalid table name");
4868
+ if (!isString(table)) throw new Error("Invalid table name");
5117
4869
  if (__privateGet$1(this, _tables)[table] === void 0) {
5118
4870
  __privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: pluginOptions.tables });
5119
4871
  }
@@ -5204,30 +4956,23 @@ function getContentType(file) {
5204
4956
  return "application/octet-stream";
5205
4957
  }
5206
4958
 
5207
- var __accessCheck$1 = (obj, member, msg) => {
5208
- if (!member.has(obj))
5209
- throw TypeError("Cannot " + msg);
5210
- };
5211
- var __privateAdd$1 = (obj, member, value) => {
5212
- if (member.has(obj))
5213
- throw TypeError("Cannot add the same private member more than once");
5214
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
4959
+ var __typeError$1 = (msg) => {
4960
+ throw TypeError(msg);
5215
4961
  };
5216
- var __privateMethod$1 = (obj, member, method) => {
5217
- __accessCheck$1(obj, member, "access private method");
5218
- return method;
5219
- };
5220
- var _search, search_fn;
4962
+ var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
4963
+ var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
4964
+ var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
4965
+ var _SearchPlugin_instances, search_fn;
5221
4966
  class SearchPlugin extends XataPlugin {
5222
4967
  constructor(db) {
5223
4968
  super();
5224
4969
  this.db = db;
5225
- __privateAdd$1(this, _search);
4970
+ __privateAdd$1(this, _SearchPlugin_instances);
5226
4971
  }
5227
4972
  build(pluginOptions) {
5228
4973
  return {
5229
4974
  all: async (query, options = {}) => {
5230
- const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
4975
+ const { records, totalCount } = await __privateMethod$1(this, _SearchPlugin_instances, search_fn).call(this, query, options, pluginOptions);
5231
4976
  return {
5232
4977
  totalCount,
5233
4978
  records: records.map((record) => {
@@ -5237,7 +4982,7 @@ class SearchPlugin extends XataPlugin {
5237
4982
  };
5238
4983
  },
5239
4984
  byTable: async (query, options = {}) => {
5240
- const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
4985
+ const { records: rawRecords, totalCount } = await __privateMethod$1(this, _SearchPlugin_instances, search_fn).call(this, query, options, pluginOptions);
5241
4986
  const records = rawRecords.reduce((acc, record) => {
5242
4987
  const table = record.xata_table;
5243
4988
  const items = acc[table] ?? [];
@@ -5249,7 +4994,7 @@ class SearchPlugin extends XataPlugin {
5249
4994
  };
5250
4995
  }
5251
4996
  }
5252
- _search = new WeakSet();
4997
+ _SearchPlugin_instances = new WeakSet();
5253
4998
  search_fn = async function(query, options, pluginOptions) {
5254
4999
  const { tables, fuzziness, highlight, prefix, page } = options ?? {};
5255
5000
  const { records, totalCount } = await searchBranch({
@@ -5285,8 +5030,7 @@ function arrayString(val) {
5285
5030
  return result;
5286
5031
  }
5287
5032
  function prepareValue(value) {
5288
- if (!isDefined(value))
5289
- return null;
5033
+ if (!isDefined(value)) return null;
5290
5034
  if (value instanceof Date) {
5291
5035
  return value.toISOString();
5292
5036
  }
@@ -5365,8 +5109,7 @@ function buildDomain(host, region) {
5365
5109
  function buildConnectionString({ apiKey, workspacesApiUrl, branch }) {
5366
5110
  const url = isString(workspacesApiUrl) ? workspacesApiUrl : workspacesApiUrl("", {});
5367
5111
  const parts = parseWorkspacesUrlParts(url);
5368
- if (!parts)
5369
- throw new Error("Invalid workspaces URL");
5112
+ if (!parts) throw new Error("Invalid workspaces URL");
5370
5113
  const { workspace: workspaceSlug, region, database, host } = parts;
5371
5114
  const domain = buildDomain(host, region);
5372
5115
  const workspace = workspaceSlug.split("-").pop();
@@ -5391,39 +5134,24 @@ class TransactionPlugin extends XataPlugin {
5391
5134
  }
5392
5135
  }
5393
5136
 
5394
- var __accessCheck = (obj, member, msg) => {
5395
- if (!member.has(obj))
5396
- throw TypeError("Cannot " + msg);
5397
- };
5398
- var __privateGet = (obj, member, getter) => {
5399
- __accessCheck(obj, member, "read from private field");
5400
- return getter ? getter.call(obj) : member.get(obj);
5401
- };
5402
- var __privateAdd = (obj, member, value) => {
5403
- if (member.has(obj))
5404
- throw TypeError("Cannot add the same private member more than once");
5405
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
5406
- };
5407
- var __privateSet = (obj, member, value, setter) => {
5408
- __accessCheck(obj, member, "write to private field");
5409
- member.set(obj, value);
5410
- return value;
5411
- };
5412
- var __privateMethod = (obj, member, method) => {
5413
- __accessCheck(obj, member, "access private method");
5414
- return method;
5137
+ var __typeError = (msg) => {
5138
+ throw TypeError(msg);
5415
5139
  };
5140
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5141
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
5142
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
5143
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
5144
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
5416
5145
  const buildClient = (plugins) => {
5417
- var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
5146
+ var _options, _instances, parseOptions_fn, getFetchProps_fn, _a;
5418
5147
  return _a = class {
5419
5148
  constructor(options = {}, tables) {
5420
- __privateAdd(this, _parseOptions);
5421
- __privateAdd(this, _getFetchProps);
5422
- __privateAdd(this, _options, void 0);
5423
- const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
5149
+ __privateAdd(this, _instances);
5150
+ __privateAdd(this, _options);
5151
+ const safeOptions = __privateMethod(this, _instances, parseOptions_fn).call(this, options);
5424
5152
  __privateSet(this, _options, safeOptions);
5425
5153
  const pluginOptions = {
5426
- ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
5154
+ ...__privateMethod(this, _instances, getFetchProps_fn).call(this, safeOptions),
5427
5155
  host: safeOptions.host,
5428
5156
  tables,
5429
5157
  branch: safeOptions.branch
@@ -5440,8 +5168,7 @@ const buildClient = (plugins) => {
5440
5168
  this.sql = sql;
5441
5169
  this.files = files;
5442
5170
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
5443
- if (namespace === void 0)
5444
- continue;
5171
+ if (namespace === void 0) continue;
5445
5172
  this[key] = namespace.build(pluginOptions);
5446
5173
  }
5447
5174
  }
@@ -5450,8 +5177,8 @@ const buildClient = (plugins) => {
5450
5177
  const branch = __privateGet(this, _options).branch;
5451
5178
  return { databaseURL, branch };
5452
5179
  }
5453
- }, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
5454
- const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
5180
+ }, _options = new WeakMap(), _instances = new WeakSet(), parseOptions_fn = function(options) {
5181
+ const enableBrowser = options?.enableBrowser ?? false;
5455
5182
  const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
5456
5183
  if (isBrowser && !enableBrowser) {
5457
5184
  throw new Error(
@@ -5459,8 +5186,9 @@ const buildClient = (plugins) => {
5459
5186
  );
5460
5187
  }
5461
5188
  const fetch = getFetchImplementation(options?.fetch);
5462
- const databaseURL = options?.databaseURL || getDatabaseURL();
5463
- const apiKey = options?.apiKey || getAPIKey();
5189
+ const databaseURL = options?.databaseURL;
5190
+ const apiKey = options?.apiKey;
5191
+ const branch = options?.branch;
5464
5192
  const trace = options?.trace ?? defaultTrace;
5465
5193
  const clientName = options?.clientName;
5466
5194
  const host = options?.host ?? "production";
@@ -5471,25 +5199,8 @@ const buildClient = (plugins) => {
5471
5199
  if (!databaseURL) {
5472
5200
  throw new Error("Option databaseURL is required");
5473
5201
  }
5474
- const envBranch = getBranch();
5475
- const previewBranch = getPreviewBranch();
5476
- const branch = options?.branch || previewBranch || envBranch || "main";
5477
- if (!!previewBranch && branch !== previewBranch) {
5478
- console.warn(
5479
- `Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
5480
- );
5481
- } else if (!!envBranch && branch !== envBranch) {
5482
- console.warn(
5483
- `Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
5484
- );
5485
- } else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
5486
- console.warn(
5487
- `Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
5488
- );
5489
- } else if (!previewBranch && !envBranch && options?.branch === void 0) {
5490
- console.warn(
5491
- `No branch was passed to the client constructor. Using default branch ${branch}. You can set the branch with the environment variable XATA_BRANCH or by passing the branch option to the client constructor.`
5492
- );
5202
+ if (!branch) {
5203
+ throw new Error("Option branch is required");
5493
5204
  }
5494
5205
  return {
5495
5206
  fetch,
@@ -5503,7 +5214,7 @@ const buildClient = (plugins) => {
5503
5214
  clientName,
5504
5215
  xataAgentExtra
5505
5216
  };
5506
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
5217
+ }, getFetchProps_fn = function({
5507
5218
  fetch,
5508
5219
  apiKey,
5509
5220
  databaseURL,
@@ -5544,26 +5255,19 @@ class Serializer {
5544
5255
  }
5545
5256
  toJSON(data) {
5546
5257
  function visit(obj) {
5547
- if (Array.isArray(obj))
5548
- return obj.map(visit);
5258
+ if (Array.isArray(obj)) return obj.map(visit);
5549
5259
  const type = typeof obj;
5550
- if (type === "undefined")
5551
- return { [META]: "undefined" };
5552
- if (type === "bigint")
5553
- return { [META]: "bigint", [VALUE]: obj.toString() };
5554
- if (obj === null || type !== "object")
5555
- return obj;
5260
+ if (type === "undefined") return { [META]: "undefined" };
5261
+ if (type === "bigint") return { [META]: "bigint", [VALUE]: obj.toString() };
5262
+ if (obj === null || type !== "object") return obj;
5556
5263
  const constructor = obj.constructor;
5557
5264
  const o = { [META]: constructor.name };
5558
5265
  for (const [key, value] of Object.entries(obj)) {
5559
5266
  o[key] = visit(value);
5560
5267
  }
5561
- if (constructor === Date)
5562
- o[VALUE] = obj.toISOString();
5563
- if (constructor === Map)
5564
- o[VALUE] = Object.fromEntries(obj);
5565
- if (constructor === Set)
5566
- o[VALUE] = [...obj];
5268
+ if (constructor === Date) o[VALUE] = obj.toISOString();
5269
+ if (constructor === Map) o[VALUE] = Object.fromEntries(obj);
5270
+ if (constructor === Set) o[VALUE] = [...obj];
5567
5271
  return o;
5568
5272
  }
5569
5273
  return JSON.stringify(visit(data));
@@ -5576,16 +5280,11 @@ class Serializer {
5576
5280
  if (constructor) {
5577
5281
  return Object.assign(Object.create(constructor.prototype), rest);
5578
5282
  }
5579
- if (clazz === "Date")
5580
- return new Date(val);
5581
- if (clazz === "Set")
5582
- return new Set(val);
5583
- if (clazz === "Map")
5584
- return new Map(Object.entries(val));
5585
- if (clazz === "bigint")
5586
- return BigInt(val);
5587
- if (clazz === "undefined")
5588
- return void 0;
5283
+ if (clazz === "Date") return new Date(val);
5284
+ if (clazz === "Set") return new Set(val);
5285
+ if (clazz === "Map") return new Map(Object.entries(val));
5286
+ if (clazz === "bigint") return BigInt(val);
5287
+ if (clazz === "undefined") return void 0;
5589
5288
  return rest;
5590
5289
  }
5591
5290
  return value;
@@ -5600,6 +5299,47 @@ const deserialize = (json) => {
5600
5299
  return defaultSerializer.fromJSON(json);
5601
5300
  };
5602
5301
 
5302
+ function parseEnvironment(environment) {
5303
+ try {
5304
+ if (typeof environment === "function") {
5305
+ return new Proxy(
5306
+ {},
5307
+ {
5308
+ get(target) {
5309
+ return environment(target);
5310
+ }
5311
+ }
5312
+ );
5313
+ }
5314
+ if (isObject(environment)) {
5315
+ return environment;
5316
+ }
5317
+ } catch (error) {
5318
+ }
5319
+ return {};
5320
+ }
5321
+ function buildPreviewBranchName({ org, branch }) {
5322
+ return `preview-${org}-${branch}`;
5323
+ }
5324
+ function getDeployPreviewBranch(environment) {
5325
+ try {
5326
+ const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = parseEnvironment(environment);
5327
+ if (deployPreviewBranch) return deployPreviewBranch;
5328
+ switch (deployPreview) {
5329
+ case "vercel": {
5330
+ if (!vercelGitCommitRef || !vercelGitRepoOwner) {
5331
+ console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
5332
+ return void 0;
5333
+ }
5334
+ return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
5335
+ }
5336
+ }
5337
+ return void 0;
5338
+ } catch (err) {
5339
+ return void 0;
5340
+ }
5341
+ }
5342
+
5603
5343
  class XataError extends Error {
5604
5344
  constructor(message, status) {
5605
5345
  super(message);
@@ -5607,5 +5347,5 @@ class XataError extends Error {
5607
5347
  }
5608
5348
  }
5609
5349
 
5610
- export { BaseClient, Buffer, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, PageRecordArray, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, adaptAllTables, adaptTable, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteCluster, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, fileUpload, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationJobStatus, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseSettings, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationHistory, getMigrationJobStatus, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspaceSettings, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateDatabaseSettings, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, updateWorkspaceSettings, upsertRecordWithID, vectorSearchTable };
5350
+ export { BaseClient, Buffer, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, PageRecordArray, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, adaptAllTables, adaptTable, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, completeMigration, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteCluster, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, fileUpload, ge, getAuthorizationCode, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationJobStatus, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseSettings, getDeployPreviewBranch, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationHistory, getMigrationJobStatus, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspaceSettings, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, rollbackMigration, searchBranch, searchTable, serialize, setTableSchema, sqlBatchQuery, sqlQuery, startMigration, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateDatabaseSettings, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, updateWorkspaceSettings, upsertRecordWithID, vectorSearchTable };
5611
5351
  //# sourceMappingURL=index.mjs.map