@xata.io/client 0.0.0-next.v3c98c9e18d38b282eb80381e4bd7bf95da9aabdb → 0.0.0-next.v403cdd55cb26b69c074dbc07b44daa0c2a0a77b6

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,29 +1899,15 @@ function promiseMap(inputValues, mapper) {
1924
1899
  return inputValues.reduce(reducer, Promise.resolve([]));
1925
1900
  }
1926
1901
 
1927
- var __accessCheck$6 = (obj, member, msg) => {
1928
- if (!member.has(obj))
1929
- throw TypeError("Cannot " + msg);
1930
- };
1931
- var __privateGet$5 = (obj, member, getter) => {
1932
- __accessCheck$6(obj, member, "read from private field");
1933
- return getter ? getter.call(obj) : member.get(obj);
1934
- };
1935
- var __privateAdd$6 = (obj, member, value) => {
1936
- if (member.has(obj))
1937
- throw TypeError("Cannot add the same private member more than once");
1938
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1902
+ var __typeError$6 = (msg) => {
1903
+ throw TypeError(msg);
1939
1904
  };
1940
- var __privateSet$4 = (obj, member, value, setter) => {
1941
- __accessCheck$6(obj, member, "write to private field");
1942
- member.set(obj, value);
1943
- return value;
1944
- };
1945
- var __privateMethod$4 = (obj, member, method) => {
1946
- __accessCheck$6(obj, member, "access private method");
1947
- return method;
1948
- };
1949
- 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;
1950
1911
  const REQUEST_TIMEOUT = 5 * 60 * 1e3;
1951
1912
  function getFetchImplementation(userFetch) {
1952
1913
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
@@ -1959,10 +1920,10 @@ function getFetchImplementation(userFetch) {
1959
1920
  }
1960
1921
  class ApiRequestPool {
1961
1922
  constructor(concurrency = 10) {
1962
- __privateAdd$6(this, _enqueue);
1963
- __privateAdd$6(this, _fetch, void 0);
1964
- __privateAdd$6(this, _queue, void 0);
1965
- __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);
1966
1927
  __privateSet$4(this, _queue, []);
1967
1928
  __privateSet$4(this, _concurrency, concurrency);
1968
1929
  this.running = 0;
@@ -1997,7 +1958,7 @@ class ApiRequestPool {
1997
1958
  }
1998
1959
  return response;
1999
1960
  };
2000
- return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
1961
+ return __privateMethod$4(this, _ApiRequestPool_instances, enqueue_fn).call(this, async () => {
2001
1962
  return await runRequest();
2002
1963
  });
2003
1964
  }
@@ -2005,7 +1966,7 @@ class ApiRequestPool {
2005
1966
  _fetch = new WeakMap();
2006
1967
  _queue = new WeakMap();
2007
1968
  _concurrency = new WeakMap();
2008
- _enqueue = new WeakSet();
1969
+ _ApiRequestPool_instances = new WeakSet();
2009
1970
  enqueue_fn = function(task) {
2010
1971
  const promise = new Promise((resolve) => __privateGet$5(this, _queue).push(resolve)).finally(() => {
2011
1972
  this.started--;
@@ -2208,7 +2169,7 @@ function defaultOnOpen(response) {
2208
2169
  }
2209
2170
  }
2210
2171
 
2211
- const VERSION = "0.29.4";
2172
+ const VERSION = "0.30.0";
2212
2173
 
2213
2174
  class ErrorWithCause extends Error {
2214
2175
  constructor(message, options) {
@@ -2288,18 +2249,15 @@ function parseProviderString(provider = "production") {
2288
2249
  return provider;
2289
2250
  }
2290
2251
  const [main, workspaces] = provider.split(",");
2291
- if (!main || !workspaces)
2292
- return null;
2252
+ if (!main || !workspaces) return null;
2293
2253
  return { main, workspaces };
2294
2254
  }
2295
2255
  function buildProviderString(provider) {
2296
- if (isHostProviderAlias(provider))
2297
- return provider;
2256
+ if (isHostProviderAlias(provider)) return provider;
2298
2257
  return `${provider.main},${provider.workspaces}`;
2299
2258
  }
2300
2259
  function parseWorkspacesUrlParts(url) {
2301
- if (!isString(url))
2302
- return null;
2260
+ if (!isString(url)) return null;
2303
2261
  const matches = {
2304
2262
  production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh\/db\/([^:]+):?(.*)?/),
2305
2263
  staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev\/db\/([^:]+):?(.*)?/),
@@ -2307,16 +2265,14 @@ function parseWorkspacesUrlParts(url) {
2307
2265
  local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(?:\d+)\/db\/([^:]+):?(.*)?/)
2308
2266
  };
2309
2267
  const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
2310
- if (!isHostProviderAlias(host) || !match)
2311
- return null;
2268
+ if (!isHostProviderAlias(host) || !match) return null;
2312
2269
  return { workspace: match[1], region: match[2], database: match[3], branch: match[4], host };
2313
2270
  }
2314
2271
 
2315
2272
  const pool = new ApiRequestPool();
2316
2273
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
2317
2274
  const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
2318
- if (value === void 0 || value === null)
2319
- return acc;
2275
+ if (value === void 0 || value === null) return acc;
2320
2276
  return { ...acc, [key]: value };
2321
2277
  }, {});
2322
2278
  const query = new URLSearchParams(cleanQueryParams).toString();
@@ -2364,8 +2320,7 @@ function hostHeader(url) {
2364
2320
  return groups?.host ? { Host: groups.host } : {};
2365
2321
  }
2366
2322
  async function parseBody(body, headers) {
2367
- if (!isDefined(body))
2368
- return void 0;
2323
+ if (!isDefined(body)) return void 0;
2369
2324
  if (isBlob(body) || typeof body.text === "function") {
2370
2325
  return body;
2371
2326
  }
@@ -2444,8 +2399,7 @@ async function fetch$1({
2444
2399
  [TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
2445
2400
  });
2446
2401
  const message = response.headers?.get("x-xata-message");
2447
- if (message)
2448
- console.warn(message);
2402
+ if (message) console.warn(message);
2449
2403
  if (response.status === 204) {
2450
2404
  return {};
2451
2405
  }
@@ -2529,12 +2483,72 @@ function parseUrl(url) {
2529
2483
 
2530
2484
  const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
2531
2485
 
2486
+ const getTasks = (variables, signal) => dataPlaneFetch({
2487
+ url: "/tasks",
2488
+ method: "get",
2489
+ ...variables,
2490
+ signal
2491
+ });
2492
+ const getTaskStatus = (variables, signal) => dataPlaneFetch({
2493
+ url: "/tasks/{taskId}",
2494
+ method: "get",
2495
+ ...variables,
2496
+ signal
2497
+ });
2498
+ const listClusterBranches = (variables, signal) => dataPlaneFetch({
2499
+ url: "/cluster/{clusterId}/branches",
2500
+ method: "get",
2501
+ ...variables,
2502
+ signal
2503
+ });
2504
+ const listClusterExtensions = (variables, signal) => dataPlaneFetch({
2505
+ url: "/cluster/{clusterId}/extensions",
2506
+ method: "get",
2507
+ ...variables,
2508
+ signal
2509
+ });
2510
+ const installClusterExtension = (variables, signal) => dataPlaneFetch({
2511
+ url: "/cluster/{clusterId}/extensions",
2512
+ method: "post",
2513
+ ...variables,
2514
+ signal
2515
+ });
2516
+ const dropClusterExtension = (variables, signal) => dataPlaneFetch({
2517
+ url: "/cluster/{clusterId}/extensions",
2518
+ method: "delete",
2519
+ ...variables,
2520
+ signal
2521
+ });
2522
+ const getClusterMetrics = (variables, signal) => dataPlaneFetch({
2523
+ url: "/cluster/{clusterId}/metrics",
2524
+ method: "get",
2525
+ ...variables,
2526
+ signal
2527
+ });
2532
2528
  const applyMigration = (variables, signal) => dataPlaneFetch({
2533
2529
  url: "/db/{dbBranchName}/migrations/apply",
2534
2530
  method: "post",
2535
2531
  ...variables,
2536
2532
  signal
2537
2533
  });
2534
+ const startMigration = (variables, signal) => dataPlaneFetch({
2535
+ url: "/db/{dbBranchName}/migrations/start",
2536
+ method: "post",
2537
+ ...variables,
2538
+ signal
2539
+ });
2540
+ const completeMigration = (variables, signal) => dataPlaneFetch({
2541
+ url: "/db/{dbBranchName}/migrations/complete",
2542
+ method: "post",
2543
+ ...variables,
2544
+ signal
2545
+ });
2546
+ const rollbackMigration = (variables, signal) => dataPlaneFetch({
2547
+ url: "/db/{dbBranchName}/migrations/rollback",
2548
+ method: "post",
2549
+ ...variables,
2550
+ signal
2551
+ });
2538
2552
  const adaptTable = (variables, signal) => dataPlaneFetch({
2539
2553
  url: "/db/{dbBranchName}/migrations/adapt/{tableName}",
2540
2554
  method: "post",
@@ -2553,6 +2567,12 @@ const getBranchMigrationJobStatus = (variables, signal) => dataPlaneFetch({
2553
2567
  ...variables,
2554
2568
  signal
2555
2569
  });
2570
+ const getMigrationJobs = (variables, signal) => dataPlaneFetch({
2571
+ url: "/db/{dbBranchName}/migrations/jobs",
2572
+ method: "get",
2573
+ ...variables,
2574
+ signal
2575
+ });
2556
2576
  const getMigrationJobStatus = (variables, signal) => dataPlaneFetch({
2557
2577
  url: "/db/{dbBranchName}/migrations/jobs/{jobId}",
2558
2578
  method: "get",
@@ -2578,6 +2598,7 @@ const getDatabaseSettings = (variables, signal) => dataPlaneFetch({
2578
2598
  signal
2579
2599
  });
2580
2600
  const updateDatabaseSettings = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/settings", method: "patch", ...variables, signal });
2601
+ const createBranchAsync = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/async", method: "put", ...variables, signal });
2581
2602
  const getBranchDetails = (variables, signal) => dataPlaneFetch({
2582
2603
  url: "/db/{dbBranchName}",
2583
2604
  method: "get",
@@ -2597,12 +2618,25 @@ const getSchema = (variables, signal) => dataPlaneFetch({
2597
2618
  ...variables,
2598
2619
  signal
2599
2620
  });
2621
+ const getSchemas = (variables, signal) => dataPlaneFetch({
2622
+ url: "/db/{dbBranchName}/schemas",
2623
+ method: "get",
2624
+ ...variables,
2625
+ signal
2626
+ });
2600
2627
  const copyBranch = (variables, signal) => dataPlaneFetch({
2601
2628
  url: "/db/{dbBranchName}/copy",
2602
2629
  method: "post",
2603
2630
  ...variables,
2604
2631
  signal
2605
2632
  });
2633
+ const getBranchMoveStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/move", method: "get", ...variables, signal });
2634
+ const moveBranch = (variables, signal) => dataPlaneFetch({
2635
+ url: "/db/{dbBranchName}/move",
2636
+ method: "put",
2637
+ ...variables,
2638
+ signal
2639
+ });
2606
2640
  const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
2607
2641
  url: "/db/{dbBranchName}/metadata",
2608
2642
  method: "put",
@@ -2950,15 +2984,34 @@ const sqlQuery = (variables, signal) => dataPlaneFetch({
2950
2984
  ...variables,
2951
2985
  signal
2952
2986
  });
2987
+ const sqlBatchQuery = (variables, signal) => dataPlaneFetch({
2988
+ url: "/db/{dbBranchName}/sql/batch",
2989
+ method: "post",
2990
+ ...variables,
2991
+ signal
2992
+ });
2953
2993
  const operationsByTag$2 = {
2994
+ tasks: { getTasks, getTaskStatus },
2995
+ cluster: {
2996
+ listClusterBranches,
2997
+ listClusterExtensions,
2998
+ installClusterExtension,
2999
+ dropClusterExtension,
3000
+ getClusterMetrics
3001
+ },
2954
3002
  migrations: {
2955
3003
  applyMigration,
3004
+ startMigration,
3005
+ completeMigration,
3006
+ rollbackMigration,
2956
3007
  adaptTable,
2957
3008
  adaptAllTables,
2958
3009
  getBranchMigrationJobStatus,
3010
+ getMigrationJobs,
2959
3011
  getMigrationJobStatus,
2960
3012
  getMigrationHistory,
2961
3013
  getSchema,
3014
+ getSchemas,
2962
3015
  getBranchMigrationHistory,
2963
3016
  getBranchMigrationPlan,
2964
3017
  executeBranchMigrationPlan,
@@ -2972,10 +3025,13 @@ const operationsByTag$2 = {
2972
3025
  },
2973
3026
  branch: {
2974
3027
  getBranchList,
3028
+ createBranchAsync,
2975
3029
  getBranchDetails,
2976
3030
  createBranch,
2977
3031
  deleteBranch,
2978
3032
  copyBranch,
3033
+ getBranchMoveStatus,
3034
+ moveBranch,
2979
3035
  updateBranchMetadata,
2980
3036
  getBranchMetadata,
2981
3037
  getBranchStats,
@@ -3037,7 +3093,7 @@ const operationsByTag$2 = {
3037
3093
  summarizeTable,
3038
3094
  aggregateTable
3039
3095
  },
3040
- sql: { sqlQuery }
3096
+ sql: { sqlQuery, sqlBatchQuery }
3041
3097
  };
3042
3098
 
3043
3099
  const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
@@ -3414,8 +3470,7 @@ function buildTransformString(transformations) {
3414
3470
  ).join(",");
3415
3471
  }
3416
3472
  function transformImage(url, ...transformations) {
3417
- if (!isDefined(url))
3418
- return void 0;
3473
+ if (!isDefined(url)) return void 0;
3419
3474
  const newTransformations = buildTransformString(transformations);
3420
3475
  const { hostname, pathname, search } = new URL(url);
3421
3476
  const pathParts = pathname.split("/");
@@ -3528,8 +3583,7 @@ class XataFile {
3528
3583
  }
3529
3584
  }
3530
3585
  const parseInputFileEntry = async (entry) => {
3531
- if (!isDefined(entry))
3532
- return null;
3586
+ if (!isDefined(entry)) return null;
3533
3587
  const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
3534
3588
  return compactObject({
3535
3589
  id,
@@ -3544,24 +3598,19 @@ const parseInputFileEntry = async (entry) => {
3544
3598
  };
3545
3599
 
3546
3600
  function cleanFilter(filter) {
3547
- if (!isDefined(filter))
3548
- return void 0;
3549
- if (!isObject(filter))
3550
- return filter;
3601
+ if (!isDefined(filter)) return void 0;
3602
+ if (!isObject(filter)) return filter;
3551
3603
  const values = Object.fromEntries(
3552
3604
  Object.entries(filter).reduce((acc, [key, value]) => {
3553
- if (!isDefined(value))
3554
- return acc;
3605
+ if (!isDefined(value)) return acc;
3555
3606
  if (Array.isArray(value)) {
3556
3607
  const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
3557
- if (clean.length === 0)
3558
- return acc;
3608
+ if (clean.length === 0) return acc;
3559
3609
  return [...acc, [key, clean]];
3560
3610
  }
3561
3611
  if (isObject(value)) {
3562
3612
  const clean = cleanFilter(value);
3563
- if (!isDefined(clean))
3564
- return acc;
3613
+ if (!isDefined(clean)) return acc;
3565
3614
  return [...acc, [key, clean]];
3566
3615
  }
3567
3616
  return [...acc, [key, value]];
@@ -3571,10 +3620,8 @@ function cleanFilter(filter) {
3571
3620
  }
3572
3621
 
3573
3622
  function stringifyJson(value) {
3574
- if (!isDefined(value))
3575
- return value;
3576
- if (isString(value))
3577
- return value;
3623
+ if (!isDefined(value)) return value;
3624
+ if (isString(value)) return value;
3578
3625
  try {
3579
3626
  return JSON.stringify(value);
3580
3627
  } catch (e) {
@@ -3589,28 +3636,17 @@ function parseJson(value) {
3589
3636
  }
3590
3637
  }
3591
3638
 
3592
- var __accessCheck$5 = (obj, member, msg) => {
3593
- if (!member.has(obj))
3594
- throw TypeError("Cannot " + msg);
3595
- };
3596
- var __privateGet$4 = (obj, member, getter) => {
3597
- __accessCheck$5(obj, member, "read from private field");
3598
- return getter ? getter.call(obj) : member.get(obj);
3599
- };
3600
- var __privateAdd$5 = (obj, member, value) => {
3601
- if (member.has(obj))
3602
- throw TypeError("Cannot add the same private member more than once");
3603
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3604
- };
3605
- var __privateSet$3 = (obj, member, value, setter) => {
3606
- __accessCheck$5(obj, member, "write to private field");
3607
- member.set(obj, value);
3608
- return value;
3639
+ var __typeError$5 = (msg) => {
3640
+ throw TypeError(msg);
3609
3641
  };
3642
+ var __accessCheck$5 = (obj, member, msg) => member.has(obj) || __typeError$5("Cannot " + msg);
3643
+ var __privateGet$4 = (obj, member, getter) => (__accessCheck$5(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
3644
+ 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);
3645
+ var __privateSet$3 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value);
3610
3646
  var _query, _page;
3611
3647
  class Page {
3612
3648
  constructor(query, meta, records = []) {
3613
- __privateAdd$5(this, _query, void 0);
3649
+ __privateAdd$5(this, _query);
3614
3650
  __privateSet$3(this, _query, query);
3615
3651
  this.meta = meta;
3616
3652
  this.records = new PageRecordArray(this, records);
@@ -3697,7 +3733,7 @@ class RecordArray extends Array {
3697
3733
  const _PageRecordArray = class _PageRecordArray extends Array {
3698
3734
  constructor(...args) {
3699
3735
  super(..._PageRecordArray.parseConstructorParams(...args));
3700
- __privateAdd$5(this, _page, void 0);
3736
+ __privateAdd$5(this, _page);
3701
3737
  __privateSet$3(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
3702
3738
  }
3703
3739
  static parseConstructorParams(...args) {
@@ -3768,34 +3804,20 @@ const _PageRecordArray = class _PageRecordArray extends Array {
3768
3804
  _page = new WeakMap();
3769
3805
  let PageRecordArray = _PageRecordArray;
3770
3806
 
3771
- var __accessCheck$4 = (obj, member, msg) => {
3772
- if (!member.has(obj))
3773
- throw TypeError("Cannot " + msg);
3774
- };
3775
- var __privateGet$3 = (obj, member, getter) => {
3776
- __accessCheck$4(obj, member, "read from private field");
3777
- return getter ? getter.call(obj) : member.get(obj);
3778
- };
3779
- var __privateAdd$4 = (obj, member, value) => {
3780
- if (member.has(obj))
3781
- throw TypeError("Cannot add the same private member more than once");
3782
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3807
+ var __typeError$4 = (msg) => {
3808
+ throw TypeError(msg);
3783
3809
  };
3784
- var __privateSet$2 = (obj, member, value, setter) => {
3785
- __accessCheck$4(obj, member, "write to private field");
3786
- member.set(obj, value);
3787
- return value;
3788
- };
3789
- var __privateMethod$3 = (obj, member, method) => {
3790
- __accessCheck$4(obj, member, "access private method");
3791
- return method;
3792
- };
3793
- var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
3810
+ var __accessCheck$4 = (obj, member, msg) => member.has(obj) || __typeError$4("Cannot " + msg);
3811
+ var __privateGet$3 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
3812
+ 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);
3813
+ var __privateSet$2 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value);
3814
+ var __privateMethod$3 = (obj, member, method) => (__accessCheck$4(obj, member, "access private method"), method);
3815
+ var _table$1, _repository, _data, _Query_instances, cleanFilterConstraint_fn;
3794
3816
  const _Query = class _Query {
3795
3817
  constructor(repository, table, data, rawParent) {
3796
- __privateAdd$4(this, _cleanFilterConstraint);
3797
- __privateAdd$4(this, _table$1, void 0);
3798
- __privateAdd$4(this, _repository, void 0);
3818
+ __privateAdd$4(this, _Query_instances);
3819
+ __privateAdd$4(this, _table$1);
3820
+ __privateAdd$4(this, _repository);
3799
3821
  __privateAdd$4(this, _data, { filter: {} });
3800
3822
  // Implements pagination
3801
3823
  this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
@@ -3873,12 +3895,12 @@ const _Query = class _Query {
3873
3895
  filter(a, b) {
3874
3896
  if (arguments.length === 1) {
3875
3897
  const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
3876
- [column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
3898
+ [column]: __privateMethod$3(this, _Query_instances, cleanFilterConstraint_fn).call(this, column, constraint)
3877
3899
  }));
3878
3900
  const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat(constraints));
3879
3901
  return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
3880
3902
  } else {
3881
- const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
3903
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _Query_instances, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
3882
3904
  const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat(constraints));
3883
3905
  return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
3884
3906
  }
@@ -3957,8 +3979,7 @@ const _Query = class _Query {
3957
3979
  }
3958
3980
  async getFirstOrThrow(options = {}) {
3959
3981
  const records = await this.getMany({ ...options, pagination: { size: 1 } });
3960
- if (records[0] === void 0)
3961
- throw new Error("No results found.");
3982
+ if (records[0] === void 0) throw new Error("No results found.");
3962
3983
  return records[0];
3963
3984
  }
3964
3985
  async summarize(params = {}) {
@@ -4013,7 +4034,7 @@ const _Query = class _Query {
4013
4034
  _table$1 = new WeakMap();
4014
4035
  _repository = new WeakMap();
4015
4036
  _data = new WeakMap();
4016
- _cleanFilterConstraint = new WeakSet();
4037
+ _Query_instances = new WeakSet();
4017
4038
  cleanFilterConstraint_fn = function(column, value) {
4018
4039
  const columnType = __privateGet$3(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
4019
4040
  if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
@@ -4074,8 +4095,7 @@ function isSortFilterString(value) {
4074
4095
  }
4075
4096
  function isSortFilterBase(filter) {
4076
4097
  return isObject(filter) && Object.entries(filter).every(([key, value]) => {
4077
- if (key === "*")
4078
- return value === "random";
4098
+ if (key === "*") return value === "random";
4079
4099
  return value === "asc" || value === "desc";
4080
4100
  });
4081
4101
  }
@@ -4096,29 +4116,15 @@ function buildSortFilter(filter) {
4096
4116
  }
4097
4117
  }
4098
4118
 
4099
- var __accessCheck$3 = (obj, member, msg) => {
4100
- if (!member.has(obj))
4101
- throw TypeError("Cannot " + msg);
4102
- };
4103
- var __privateGet$2 = (obj, member, getter) => {
4104
- __accessCheck$3(obj, member, "read from private field");
4105
- return getter ? getter.call(obj) : member.get(obj);
4106
- };
4107
- var __privateAdd$3 = (obj, member, value) => {
4108
- if (member.has(obj))
4109
- throw TypeError("Cannot add the same private member more than once");
4110
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
4111
- };
4112
- var __privateSet$1 = (obj, member, value, setter) => {
4113
- __accessCheck$3(obj, member, "write to private field");
4114
- member.set(obj, value);
4115
- return value;
4119
+ var __typeError$3 = (msg) => {
4120
+ throw TypeError(msg);
4116
4121
  };
4117
- var __privateMethod$2 = (obj, member, method) => {
4118
- __accessCheck$3(obj, member, "access private method");
4119
- return method;
4120
- };
4121
- 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;
4122
+ var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
4123
+ var __privateGet$2 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
4124
+ 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);
4125
+ var __privateSet$1 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value);
4126
+ var __privateMethod$2 = (obj, member, method) => (__accessCheck$3(obj, member, "access private method"), method);
4127
+ 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;
4122
4128
  const BULK_OPERATION_MAX_SIZE = 1e3;
4123
4129
  class Repository extends Query {
4124
4130
  }
@@ -4129,21 +4135,12 @@ class RestRepository extends Query {
4129
4135
  { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
4130
4136
  {}
4131
4137
  );
4132
- __privateAdd$3(this, _insertRecordWithoutId);
4133
- __privateAdd$3(this, _insertRecordWithId);
4134
- __privateAdd$3(this, _insertRecords);
4135
- __privateAdd$3(this, _updateRecordWithID);
4136
- __privateAdd$3(this, _updateRecords);
4137
- __privateAdd$3(this, _upsertRecordWithID);
4138
- __privateAdd$3(this, _deleteRecord);
4139
- __privateAdd$3(this, _deleteRecords);
4140
- __privateAdd$3(this, _getSchemaTables);
4141
- __privateAdd$3(this, _transformObjectToApi);
4142
- __privateAdd$3(this, _table, void 0);
4143
- __privateAdd$3(this, _getFetchProps, void 0);
4144
- __privateAdd$3(this, _db, void 0);
4145
- __privateAdd$3(this, _schemaTables, void 0);
4146
- __privateAdd$3(this, _trace, void 0);
4138
+ __privateAdd$3(this, _RestRepository_instances);
4139
+ __privateAdd$3(this, _table);
4140
+ __privateAdd$3(this, _getFetchProps);
4141
+ __privateAdd$3(this, _db);
4142
+ __privateAdd$3(this, _schemaTables);
4143
+ __privateAdd$3(this, _trace);
4147
4144
  __privateSet$1(this, _table, options.table);
4148
4145
  __privateSet$1(this, _db, options.db);
4149
4146
  __privateSet$1(this, _schemaTables, options.schemaTables);
@@ -4162,31 +4159,28 @@ class RestRepository extends Query {
4162
4159
  return __privateGet$2(this, _trace).call(this, "create", async () => {
4163
4160
  const ifVersion = parseIfVersion(b, c, d);
4164
4161
  if (Array.isArray(a)) {
4165
- if (a.length === 0)
4166
- return [];
4167
- const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
4162
+ if (a.length === 0) return [];
4163
+ const ids = await __privateMethod$2(this, _RestRepository_instances, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
4168
4164
  const columns = isValidSelectableColumns(b) ? b : ["*"];
4169
4165
  const result = await this.read(ids, columns);
4170
4166
  return result;
4171
4167
  }
4172
4168
  if (isString(a) && isObject(b)) {
4173
- if (a === "")
4174
- throw new Error("The id can't be empty");
4169
+ if (a === "") throw new Error("The id can't be empty");
4175
4170
  const columns = isValidSelectableColumns(c) ? c : void 0;
4176
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
4171
+ return await __privateMethod$2(this, _RestRepository_instances, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
4177
4172
  }
4178
4173
  if (isObject(a) && isString(a.xata_id)) {
4179
- if (a.xata_id === "")
4180
- throw new Error("The id can't be empty");
4174
+ if (a.xata_id === "") throw new Error("The id can't be empty");
4181
4175
  const columns = isValidSelectableColumns(b) ? b : void 0;
4182
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
4176
+ return await __privateMethod$2(this, _RestRepository_instances, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
4183
4177
  createOnly: true,
4184
4178
  ifVersion
4185
4179
  });
4186
4180
  }
4187
4181
  if (isObject(a)) {
4188
4182
  const columns = isValidSelectableColumns(b) ? b : void 0;
4189
- return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
4183
+ return __privateMethod$2(this, _RestRepository_instances, insertRecordWithoutId_fn).call(this, a, columns);
4190
4184
  }
4191
4185
  throw new Error("Invalid arguments for create method");
4192
4186
  });
@@ -4195,8 +4189,7 @@ class RestRepository extends Query {
4195
4189
  return __privateGet$2(this, _trace).call(this, "read", async () => {
4196
4190
  const columns = isValidSelectableColumns(b) ? b : ["*"];
4197
4191
  if (Array.isArray(a)) {
4198
- if (a.length === 0)
4199
- return [];
4192
+ if (a.length === 0) return [];
4200
4193
  const ids = a.map((item) => extractId(item));
4201
4194
  const finalObjects = await this.getAll({ filter: { xata_id: { $any: compact(ids) } }, columns });
4202
4195
  const dictionary = finalObjects.reduce((acc, object) => {
@@ -4219,7 +4212,7 @@ class RestRepository extends Query {
4219
4212
  queryParams: { columns },
4220
4213
  ...__privateGet$2(this, _getFetchProps).call(this)
4221
4214
  });
4222
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4215
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4223
4216
  return initObject(
4224
4217
  __privateGet$2(this, _db),
4225
4218
  schemaTables,
@@ -4260,11 +4253,10 @@ class RestRepository extends Query {
4260
4253
  return __privateGet$2(this, _trace).call(this, "update", async () => {
4261
4254
  const ifVersion = parseIfVersion(b, c, d);
4262
4255
  if (Array.isArray(a)) {
4263
- if (a.length === 0)
4264
- return [];
4256
+ if (a.length === 0) return [];
4265
4257
  const existing = await this.read(a, ["xata_id"]);
4266
4258
  const updates = a.filter((_item, index) => existing[index] !== null);
4267
- await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
4259
+ await __privateMethod$2(this, _RestRepository_instances, updateRecords_fn).call(this, updates, {
4268
4260
  ifVersion,
4269
4261
  upsert: false
4270
4262
  });
@@ -4275,15 +4267,14 @@ class RestRepository extends Query {
4275
4267
  try {
4276
4268
  if (isString(a) && isObject(b)) {
4277
4269
  const columns = isValidSelectableColumns(c) ? c : void 0;
4278
- return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
4270
+ return await __privateMethod$2(this, _RestRepository_instances, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
4279
4271
  }
4280
4272
  if (isObject(a) && isString(a.xata_id)) {
4281
4273
  const columns = isValidSelectableColumns(b) ? b : void 0;
4282
- return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
4274
+ return await __privateMethod$2(this, _RestRepository_instances, updateRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
4283
4275
  }
4284
4276
  } catch (error) {
4285
- if (error.status === 422)
4286
- return null;
4277
+ if (error.status === 422) return null;
4287
4278
  throw error;
4288
4279
  }
4289
4280
  throw new Error("Invalid arguments for update method");
@@ -4312,9 +4303,8 @@ class RestRepository extends Query {
4312
4303
  return __privateGet$2(this, _trace).call(this, "createOrUpdate", async () => {
4313
4304
  const ifVersion = parseIfVersion(b, c, d);
4314
4305
  if (Array.isArray(a)) {
4315
- if (a.length === 0)
4316
- return [];
4317
- await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
4306
+ if (a.length === 0) return [];
4307
+ await __privateMethod$2(this, _RestRepository_instances, updateRecords_fn).call(this, a, {
4318
4308
  ifVersion,
4319
4309
  upsert: true
4320
4310
  });
@@ -4323,16 +4313,14 @@ class RestRepository extends Query {
4323
4313
  return result;
4324
4314
  }
4325
4315
  if (isString(a) && isObject(b)) {
4326
- if (a === "")
4327
- throw new Error("The id can't be empty");
4316
+ if (a === "") throw new Error("The id can't be empty");
4328
4317
  const columns = isValidSelectableColumns(c) ? c : void 0;
4329
- return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
4318
+ return await __privateMethod$2(this, _RestRepository_instances, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
4330
4319
  }
4331
4320
  if (isObject(a) && isString(a.xata_id)) {
4332
- if (a.xata_id === "")
4333
- throw new Error("The id can't be empty");
4321
+ if (a.xata_id === "") throw new Error("The id can't be empty");
4334
4322
  const columns = isValidSelectableColumns(c) ? c : void 0;
4335
- return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
4323
+ return await __privateMethod$2(this, _RestRepository_instances, upsertRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
4336
4324
  }
4337
4325
  if (!isDefined(a) && isObject(b)) {
4338
4326
  return await this.create(b, c);
@@ -4347,24 +4335,21 @@ class RestRepository extends Query {
4347
4335
  return __privateGet$2(this, _trace).call(this, "createOrReplace", async () => {
4348
4336
  const ifVersion = parseIfVersion(b, c, d);
4349
4337
  if (Array.isArray(a)) {
4350
- if (a.length === 0)
4351
- return [];
4352
- const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
4338
+ if (a.length === 0) return [];
4339
+ const ids = await __privateMethod$2(this, _RestRepository_instances, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
4353
4340
  const columns = isValidSelectableColumns(b) ? b : ["*"];
4354
4341
  const result = await this.read(ids, columns);
4355
4342
  return result;
4356
4343
  }
4357
4344
  if (isString(a) && isObject(b)) {
4358
- if (a === "")
4359
- throw new Error("The id can't be empty");
4345
+ if (a === "") throw new Error("The id can't be empty");
4360
4346
  const columns = isValidSelectableColumns(c) ? c : void 0;
4361
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
4347
+ return await __privateMethod$2(this, _RestRepository_instances, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
4362
4348
  }
4363
4349
  if (isObject(a) && isString(a.xata_id)) {
4364
- if (a.xata_id === "")
4365
- throw new Error("The id can't be empty");
4350
+ if (a.xata_id === "") throw new Error("The id can't be empty");
4366
4351
  const columns = isValidSelectableColumns(c) ? c : void 0;
4367
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
4352
+ return await __privateMethod$2(this, _RestRepository_instances, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
4368
4353
  createOnly: false,
4369
4354
  ifVersion
4370
4355
  });
@@ -4381,25 +4366,22 @@ class RestRepository extends Query {
4381
4366
  async delete(a, b) {
4382
4367
  return __privateGet$2(this, _trace).call(this, "delete", async () => {
4383
4368
  if (Array.isArray(a)) {
4384
- if (a.length === 0)
4385
- return [];
4369
+ if (a.length === 0) return [];
4386
4370
  const ids = a.map((o) => {
4387
- if (isString(o))
4388
- return o;
4389
- if (isString(o.xata_id))
4390
- return o.xata_id;
4371
+ if (isString(o)) return o;
4372
+ if (isString(o.xata_id)) return o.xata_id;
4391
4373
  throw new Error("Invalid arguments for delete method");
4392
4374
  });
4393
4375
  const columns = isValidSelectableColumns(b) ? b : ["*"];
4394
4376
  const result = await this.read(a, columns);
4395
- await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
4377
+ await __privateMethod$2(this, _RestRepository_instances, deleteRecords_fn).call(this, ids);
4396
4378
  return result;
4397
4379
  }
4398
4380
  if (isString(a)) {
4399
- return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
4381
+ return __privateMethod$2(this, _RestRepository_instances, deleteRecord_fn).call(this, a, b);
4400
4382
  }
4401
4383
  if (isObject(a) && isString(a.xata_id)) {
4402
- return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.xata_id, b);
4384
+ return __privateMethod$2(this, _RestRepository_instances, deleteRecord_fn).call(this, a.xata_id, b);
4403
4385
  }
4404
4386
  throw new Error("Invalid arguments for delete method");
4405
4387
  });
@@ -4443,7 +4425,7 @@ class RestRepository extends Query {
4443
4425
  },
4444
4426
  ...__privateGet$2(this, _getFetchProps).call(this)
4445
4427
  });
4446
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4428
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4447
4429
  return {
4448
4430
  records: records.map((item) => initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), item, ["*"])),
4449
4431
  totalCount
@@ -4468,7 +4450,7 @@ class RestRepository extends Query {
4468
4450
  },
4469
4451
  ...__privateGet$2(this, _getFetchProps).call(this)
4470
4452
  });
4471
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4453
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4472
4454
  return {
4473
4455
  records: records.map((item) => initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), item, ["*"])),
4474
4456
  totalCount
@@ -4510,7 +4492,7 @@ class RestRepository extends Query {
4510
4492
  fetchOptions: data.fetchOptions,
4511
4493
  ...__privateGet$2(this, _getFetchProps).call(this)
4512
4494
  });
4513
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4495
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4514
4496
  const records = objects.map(
4515
4497
  (record) => initObject(
4516
4498
  __privateGet$2(this, _db),
@@ -4544,7 +4526,7 @@ class RestRepository extends Query {
4544
4526
  },
4545
4527
  ...__privateGet$2(this, _getFetchProps).call(this)
4546
4528
  });
4547
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4529
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4548
4530
  return {
4549
4531
  ...result,
4550
4532
  summaries: result.summaries.map(
@@ -4592,9 +4574,9 @@ _getFetchProps = new WeakMap();
4592
4574
  _db = new WeakMap();
4593
4575
  _schemaTables = new WeakMap();
4594
4576
  _trace = new WeakMap();
4595
- _insertRecordWithoutId = new WeakSet();
4577
+ _RestRepository_instances = new WeakSet();
4596
4578
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
4597
- const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
4579
+ const record = await __privateMethod$2(this, _RestRepository_instances, transformObjectToApi_fn).call(this, object);
4598
4580
  const response = await insertRecord({
4599
4581
  pathParams: {
4600
4582
  workspace: "{workspaceId}",
@@ -4606,14 +4588,12 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
4606
4588
  body: record,
4607
4589
  ...__privateGet$2(this, _getFetchProps).call(this)
4608
4590
  });
4609
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4591
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4610
4592
  return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
4611
4593
  };
4612
- _insertRecordWithId = new WeakSet();
4613
4594
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
4614
- if (!recordId)
4615
- return null;
4616
- const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
4595
+ if (!recordId) return null;
4596
+ const record = await __privateMethod$2(this, _RestRepository_instances, transformObjectToApi_fn).call(this, object);
4617
4597
  const response = await insertRecordWithID({
4618
4598
  pathParams: {
4619
4599
  workspace: "{workspaceId}",
@@ -4626,13 +4606,12 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
4626
4606
  queryParams: { createOnly, columns, ifVersion },
4627
4607
  ...__privateGet$2(this, _getFetchProps).call(this)
4628
4608
  });
4629
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4609
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4630
4610
  return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
4631
4611
  };
4632
- _insertRecords = new WeakSet();
4633
4612
  insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
4634
4613
  const operations = await promiseMap(objects, async (object) => {
4635
- const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
4614
+ const record = await __privateMethod$2(this, _RestRepository_instances, transformObjectToApi_fn).call(this, object);
4636
4615
  return { insert: { table: __privateGet$2(this, _table), record, createOnly, ifVersion } };
4637
4616
  });
4638
4617
  const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
@@ -4657,11 +4636,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
4657
4636
  }
4658
4637
  return ids;
4659
4638
  };
4660
- _updateRecordWithID = new WeakSet();
4661
4639
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
4662
- if (!recordId)
4663
- return null;
4664
- const { xata_id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
4640
+ if (!recordId) return null;
4641
+ const { xata_id: _id, ...record } = await __privateMethod$2(this, _RestRepository_instances, transformObjectToApi_fn).call(this, object);
4665
4642
  try {
4666
4643
  const response = await updateRecordWithID({
4667
4644
  pathParams: {
@@ -4675,7 +4652,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
4675
4652
  body: record,
4676
4653
  ...__privateGet$2(this, _getFetchProps).call(this)
4677
4654
  });
4678
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4655
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4679
4656
  return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
4680
4657
  } catch (e) {
4681
4658
  if (isObject(e) && e.status === 404) {
@@ -4684,10 +4661,9 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
4684
4661
  throw e;
4685
4662
  }
4686
4663
  };
4687
- _updateRecords = new WeakSet();
4688
4664
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
4689
4665
  const operations = await promiseMap(objects, async ({ xata_id, ...object }) => {
4690
- const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
4666
+ const fields = await __privateMethod$2(this, _RestRepository_instances, transformObjectToApi_fn).call(this, object);
4691
4667
  return { update: { table: __privateGet$2(this, _table), id: xata_id, ifVersion, upsert, fields } };
4692
4668
  });
4693
4669
  const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
@@ -4712,10 +4688,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
4712
4688
  }
4713
4689
  return ids;
4714
4690
  };
4715
- _upsertRecordWithID = new WeakSet();
4716
4691
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
4717
- if (!recordId)
4718
- return null;
4692
+ if (!recordId) return null;
4719
4693
  const response = await upsertRecordWithID({
4720
4694
  pathParams: {
4721
4695
  workspace: "{workspaceId}",
@@ -4728,13 +4702,11 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
4728
4702
  body: object,
4729
4703
  ...__privateGet$2(this, _getFetchProps).call(this)
4730
4704
  });
4731
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4705
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4732
4706
  return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
4733
4707
  };
4734
- _deleteRecord = new WeakSet();
4735
4708
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
4736
- if (!recordId)
4737
- return null;
4709
+ if (!recordId) return null;
4738
4710
  try {
4739
4711
  const response = await deleteRecord({
4740
4712
  pathParams: {
@@ -4747,7 +4719,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
4747
4719
  queryParams: { columns },
4748
4720
  ...__privateGet$2(this, _getFetchProps).call(this)
4749
4721
  });
4750
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4722
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4751
4723
  return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
4752
4724
  } catch (e) {
4753
4725
  if (isObject(e) && e.status === 404) {
@@ -4756,7 +4728,6 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
4756
4728
  throw e;
4757
4729
  }
4758
4730
  };
4759
- _deleteRecords = new WeakSet();
4760
4731
  deleteRecords_fn = async function(recordIds) {
4761
4732
  const chunkedOperations = chunk(
4762
4733
  compact(recordIds).map((id) => ({ delete: { table: __privateGet$2(this, _table), id } })),
@@ -4774,10 +4745,8 @@ deleteRecords_fn = async function(recordIds) {
4774
4745
  });
4775
4746
  }
4776
4747
  };
4777
- _getSchemaTables = new WeakSet();
4778
4748
  getSchemaTables_fn = async function() {
4779
- if (__privateGet$2(this, _schemaTables))
4780
- return __privateGet$2(this, _schemaTables);
4749
+ if (__privateGet$2(this, _schemaTables)) return __privateGet$2(this, _schemaTables);
4781
4750
  const { schema } = await getBranchDetails({
4782
4751
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
4783
4752
  ...__privateGet$2(this, _getFetchProps).call(this)
@@ -4785,16 +4754,13 @@ getSchemaTables_fn = async function() {
4785
4754
  __privateSet$1(this, _schemaTables, schema.tables);
4786
4755
  return schema.tables;
4787
4756
  };
4788
- _transformObjectToApi = new WeakSet();
4789
4757
  transformObjectToApi_fn = async function(object) {
4790
- const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4758
+ const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
4791
4759
  const schema = schemaTables.find((table) => table.name === __privateGet$2(this, _table));
4792
- if (!schema)
4793
- throw new Error(`Table ${__privateGet$2(this, _table)} not found in schema`);
4760
+ if (!schema) throw new Error(`Table ${__privateGet$2(this, _table)} not found in schema`);
4794
4761
  const result = {};
4795
4762
  for (const [key, value] of Object.entries(object)) {
4796
- if (["xata_version", "xata_createdat", "xata_updatedat"].includes(key))
4797
- continue;
4763
+ if (["xata_version", "xata_createdat", "xata_updatedat"].includes(key)) continue;
4798
4764
  const type = schema.columns.find((column) => column.name === key)?.type;
4799
4765
  switch (type) {
4800
4766
  case "link": {
@@ -4824,11 +4790,9 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
4824
4790
  const data = {};
4825
4791
  Object.assign(data, { ...object });
4826
4792
  const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
4827
- if (!columns)
4828
- console.error(`Table ${table} not found in schema`);
4793
+ if (!columns) console.error(`Table ${table} not found in schema`);
4829
4794
  for (const column of columns ?? []) {
4830
- if (!isValidColumn(selectedColumns, column))
4831
- continue;
4795
+ if (!isValidColumn(selectedColumns, column)) continue;
4832
4796
  const value = data[column.name];
4833
4797
  switch (column.type) {
4834
4798
  case "datetime": {
@@ -4914,15 +4878,12 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
4914
4878
  return record;
4915
4879
  };
4916
4880
  function extractId(value) {
4917
- if (isString(value))
4918
- return value;
4919
- if (isObject(value) && isString(value.xata_id))
4920
- return value.xata_id;
4881
+ if (isString(value)) return value;
4882
+ if (isObject(value) && isString(value.xata_id)) return value.xata_id;
4921
4883
  return void 0;
4922
4884
  }
4923
4885
  function isValidColumn(columns, column) {
4924
- if (columns.includes("*"))
4925
- return true;
4886
+ if (columns.includes("*")) return true;
4926
4887
  return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
4927
4888
  }
4928
4889
  function parseIfVersion(...args) {
@@ -4962,19 +4923,12 @@ const includesAll = (value) => ({ $includesAll: value });
4962
4923
  const includesNone = (value) => ({ $includesNone: value });
4963
4924
  const includesAny = (value) => ({ $includesAny: value });
4964
4925
 
4965
- var __accessCheck$2 = (obj, member, msg) => {
4966
- if (!member.has(obj))
4967
- throw TypeError("Cannot " + msg);
4968
- };
4969
- var __privateGet$1 = (obj, member, getter) => {
4970
- __accessCheck$2(obj, member, "read from private field");
4971
- return getter ? getter.call(obj) : member.get(obj);
4972
- };
4973
- var __privateAdd$2 = (obj, member, value) => {
4974
- if (member.has(obj))
4975
- throw TypeError("Cannot add the same private member more than once");
4976
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
4926
+ var __typeError$2 = (msg) => {
4927
+ throw TypeError(msg);
4977
4928
  };
4929
+ var __accessCheck$2 = (obj, member, msg) => member.has(obj) || __typeError$2("Cannot " + msg);
4930
+ var __privateGet$1 = (obj, member, getter) => (__accessCheck$2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
4931
+ 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);
4978
4932
  var _tables;
4979
4933
  class SchemaPlugin extends XataPlugin {
4980
4934
  constructor() {
@@ -4986,8 +4940,7 @@ class SchemaPlugin extends XataPlugin {
4986
4940
  {},
4987
4941
  {
4988
4942
  get: (_target, table) => {
4989
- if (!isString(table))
4990
- throw new Error("Invalid table name");
4943
+ if (!isString(table)) throw new Error("Invalid table name");
4991
4944
  if (__privateGet$1(this, _tables)[table] === void 0) {
4992
4945
  __privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: pluginOptions.tables });
4993
4946
  }
@@ -5078,30 +5031,23 @@ function getContentType(file) {
5078
5031
  return "application/octet-stream";
5079
5032
  }
5080
5033
 
5081
- var __accessCheck$1 = (obj, member, msg) => {
5082
- if (!member.has(obj))
5083
- throw TypeError("Cannot " + msg);
5084
- };
5085
- var __privateAdd$1 = (obj, member, value) => {
5086
- if (member.has(obj))
5087
- throw TypeError("Cannot add the same private member more than once");
5088
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
5089
- };
5090
- var __privateMethod$1 = (obj, member, method) => {
5091
- __accessCheck$1(obj, member, "access private method");
5092
- return method;
5034
+ var __typeError$1 = (msg) => {
5035
+ throw TypeError(msg);
5093
5036
  };
5094
- var _search, search_fn;
5037
+ var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
5038
+ 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);
5039
+ var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
5040
+ var _SearchPlugin_instances, search_fn;
5095
5041
  class SearchPlugin extends XataPlugin {
5096
5042
  constructor(db) {
5097
5043
  super();
5098
5044
  this.db = db;
5099
- __privateAdd$1(this, _search);
5045
+ __privateAdd$1(this, _SearchPlugin_instances);
5100
5046
  }
5101
5047
  build(pluginOptions) {
5102
5048
  return {
5103
5049
  all: async (query, options = {}) => {
5104
- const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
5050
+ const { records, totalCount } = await __privateMethod$1(this, _SearchPlugin_instances, search_fn).call(this, query, options, pluginOptions);
5105
5051
  return {
5106
5052
  totalCount,
5107
5053
  records: records.map((record) => {
@@ -5111,7 +5057,7 @@ class SearchPlugin extends XataPlugin {
5111
5057
  };
5112
5058
  },
5113
5059
  byTable: async (query, options = {}) => {
5114
- const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
5060
+ const { records: rawRecords, totalCount } = await __privateMethod$1(this, _SearchPlugin_instances, search_fn).call(this, query, options, pluginOptions);
5115
5061
  const records = rawRecords.reduce((acc, record) => {
5116
5062
  const table = record.xata_table;
5117
5063
  const items = acc[table] ?? [];
@@ -5123,7 +5069,7 @@ class SearchPlugin extends XataPlugin {
5123
5069
  };
5124
5070
  }
5125
5071
  }
5126
- _search = new WeakSet();
5072
+ _SearchPlugin_instances = new WeakSet();
5127
5073
  search_fn = async function(query, options, pluginOptions) {
5128
5074
  const { tables, fuzziness, highlight, prefix, page } = options ?? {};
5129
5075
  const { records, totalCount } = await searchBranch({
@@ -5159,8 +5105,7 @@ function arrayString(val) {
5159
5105
  return result;
5160
5106
  }
5161
5107
  function prepareValue(value) {
5162
- if (!isDefined(value))
5163
- return null;
5108
+ if (!isDefined(value)) return null;
5164
5109
  if (value instanceof Date) {
5165
5110
  return value.toISOString();
5166
5111
  }
@@ -5200,19 +5145,28 @@ class SQLPlugin extends XataPlugin {
5200
5145
  throw new Error("Invalid usage of `xata.sql`. Please use it as a tagged template or with an object.");
5201
5146
  }
5202
5147
  const { statement, params, consistency, responseType } = prepareParams(query, parameters);
5203
- const {
5204
- records,
5205
- rows,
5206
- warning,
5207
- columns = []
5208
- } = await sqlQuery({
5148
+ const { warning, columns, ...response } = await sqlQuery({
5209
5149
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
5210
5150
  body: { statement, params, consistency, responseType },
5211
5151
  ...pluginOptions
5212
5152
  });
5153
+ const records = "records" in response ? response.records : void 0;
5154
+ const rows = "rows" in response ? response.rows : void 0;
5213
5155
  return { records, rows, warning, columns };
5214
5156
  };
5215
5157
  sqlFunction.connectionString = buildConnectionString(pluginOptions);
5158
+ sqlFunction.batch = async (query) => {
5159
+ const { results } = await sqlBatchQuery({
5160
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
5161
+ body: {
5162
+ statements: query.statements.map(({ statement, params }) => ({ statement, params })),
5163
+ consistency: query.consistency,
5164
+ responseType: query.responseType
5165
+ },
5166
+ ...pluginOptions
5167
+ });
5168
+ return { results };
5169
+ };
5216
5170
  return sqlFunction;
5217
5171
  }
5218
5172
  }
@@ -5239,8 +5193,7 @@ function buildDomain(host, region) {
5239
5193
  function buildConnectionString({ apiKey, workspacesApiUrl, branch }) {
5240
5194
  const url = isString(workspacesApiUrl) ? workspacesApiUrl : workspacesApiUrl("", {});
5241
5195
  const parts = parseWorkspacesUrlParts(url);
5242
- if (!parts)
5243
- throw new Error("Invalid workspaces URL");
5196
+ if (!parts) throw new Error("Invalid workspaces URL");
5244
5197
  const { workspace: workspaceSlug, region, database, host } = parts;
5245
5198
  const domain = buildDomain(host, region);
5246
5199
  const workspace = workspaceSlug.split("-").pop();
@@ -5265,39 +5218,24 @@ class TransactionPlugin extends XataPlugin {
5265
5218
  }
5266
5219
  }
5267
5220
 
5268
- var __accessCheck = (obj, member, msg) => {
5269
- if (!member.has(obj))
5270
- throw TypeError("Cannot " + msg);
5271
- };
5272
- var __privateGet = (obj, member, getter) => {
5273
- __accessCheck(obj, member, "read from private field");
5274
- return getter ? getter.call(obj) : member.get(obj);
5275
- };
5276
- var __privateAdd = (obj, member, value) => {
5277
- if (member.has(obj))
5278
- throw TypeError("Cannot add the same private member more than once");
5279
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
5280
- };
5281
- var __privateSet = (obj, member, value, setter) => {
5282
- __accessCheck(obj, member, "write to private field");
5283
- member.set(obj, value);
5284
- return value;
5285
- };
5286
- var __privateMethod = (obj, member, method) => {
5287
- __accessCheck(obj, member, "access private method");
5288
- return method;
5221
+ var __typeError = (msg) => {
5222
+ throw TypeError(msg);
5289
5223
  };
5224
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5225
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
5226
+ 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);
5227
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
5228
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
5290
5229
  const buildClient = (plugins) => {
5291
- var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
5230
+ var _options, _instances, parseOptions_fn, getFetchProps_fn, _a;
5292
5231
  return _a = class {
5293
5232
  constructor(options = {}, tables) {
5294
- __privateAdd(this, _parseOptions);
5295
- __privateAdd(this, _getFetchProps);
5296
- __privateAdd(this, _options, void 0);
5297
- const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
5233
+ __privateAdd(this, _instances);
5234
+ __privateAdd(this, _options);
5235
+ const safeOptions = __privateMethod(this, _instances, parseOptions_fn).call(this, options);
5298
5236
  __privateSet(this, _options, safeOptions);
5299
5237
  const pluginOptions = {
5300
- ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
5238
+ ...__privateMethod(this, _instances, getFetchProps_fn).call(this, safeOptions),
5301
5239
  host: safeOptions.host,
5302
5240
  tables,
5303
5241
  branch: safeOptions.branch
@@ -5314,8 +5252,7 @@ const buildClient = (plugins) => {
5314
5252
  this.sql = sql;
5315
5253
  this.files = files;
5316
5254
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
5317
- if (namespace === void 0)
5318
- continue;
5255
+ if (namespace === void 0) continue;
5319
5256
  this[key] = namespace.build(pluginOptions);
5320
5257
  }
5321
5258
  }
@@ -5324,7 +5261,7 @@ const buildClient = (plugins) => {
5324
5261
  const branch = __privateGet(this, _options).branch;
5325
5262
  return { databaseURL, branch };
5326
5263
  }
5327
- }, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
5264
+ }, _options = new WeakMap(), _instances = new WeakSet(), parseOptions_fn = function(options) {
5328
5265
  const enableBrowser = options?.enableBrowser ?? false;
5329
5266
  const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
5330
5267
  if (isBrowser && !enableBrowser) {
@@ -5361,7 +5298,7 @@ const buildClient = (plugins) => {
5361
5298
  clientName,
5362
5299
  xataAgentExtra
5363
5300
  };
5364
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
5301
+ }, getFetchProps_fn = function({
5365
5302
  fetch,
5366
5303
  apiKey,
5367
5304
  databaseURL,
@@ -5402,26 +5339,19 @@ class Serializer {
5402
5339
  }
5403
5340
  toJSON(data) {
5404
5341
  function visit(obj) {
5405
- if (Array.isArray(obj))
5406
- return obj.map(visit);
5342
+ if (Array.isArray(obj)) return obj.map(visit);
5407
5343
  const type = typeof obj;
5408
- if (type === "undefined")
5409
- return { [META]: "undefined" };
5410
- if (type === "bigint")
5411
- return { [META]: "bigint", [VALUE]: obj.toString() };
5412
- if (obj === null || type !== "object")
5413
- return obj;
5344
+ if (type === "undefined") return { [META]: "undefined" };
5345
+ if (type === "bigint") return { [META]: "bigint", [VALUE]: obj.toString() };
5346
+ if (obj === null || type !== "object") return obj;
5414
5347
  const constructor = obj.constructor;
5415
5348
  const o = { [META]: constructor.name };
5416
5349
  for (const [key, value] of Object.entries(obj)) {
5417
5350
  o[key] = visit(value);
5418
5351
  }
5419
- if (constructor === Date)
5420
- o[VALUE] = obj.toISOString();
5421
- if (constructor === Map)
5422
- o[VALUE] = Object.fromEntries(obj);
5423
- if (constructor === Set)
5424
- o[VALUE] = [...obj];
5352
+ if (constructor === Date) o[VALUE] = obj.toISOString();
5353
+ if (constructor === Map) o[VALUE] = Object.fromEntries(obj);
5354
+ if (constructor === Set) o[VALUE] = [...obj];
5425
5355
  return o;
5426
5356
  }
5427
5357
  return JSON.stringify(visit(data));
@@ -5434,16 +5364,11 @@ class Serializer {
5434
5364
  if (constructor) {
5435
5365
  return Object.assign(Object.create(constructor.prototype), rest);
5436
5366
  }
5437
- if (clazz === "Date")
5438
- return new Date(val);
5439
- if (clazz === "Set")
5440
- return new Set(val);
5441
- if (clazz === "Map")
5442
- return new Map(Object.entries(val));
5443
- if (clazz === "bigint")
5444
- return BigInt(val);
5445
- if (clazz === "undefined")
5446
- return void 0;
5367
+ if (clazz === "Date") return new Date(val);
5368
+ if (clazz === "Set") return new Set(val);
5369
+ if (clazz === "Map") return new Map(Object.entries(val));
5370
+ if (clazz === "bigint") return BigInt(val);
5371
+ if (clazz === "undefined") return void 0;
5447
5372
  return rest;
5448
5373
  }
5449
5374
  return value;
@@ -5483,8 +5408,7 @@ function buildPreviewBranchName({ org, branch }) {
5483
5408
  function getDeployPreviewBranch(environment) {
5484
5409
  try {
5485
5410
  const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = parseEnvironment(environment);
5486
- if (deployPreviewBranch)
5487
- return deployPreviewBranch;
5411
+ if (deployPreviewBranch) return deployPreviewBranch;
5488
5412
  switch (deployPreview) {
5489
5413
  case "vercel": {
5490
5414
  if (!vercelGitCommitRef || !vercelGitRepoOwner) {
@@ -5507,5 +5431,5 @@ class XataError extends Error {
5507
5431
  }
5508
5432
  }
5509
5433
 
5510
- 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, 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, 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 };
5434
+ 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, createBranchAsync, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteCluster, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, dropClusterExtension, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, fileUpload, ge, getAuthorizationCode, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationJobStatus, getBranchMigrationPlan, getBranchMoveStatus, getBranchSchemaHistory, getBranchStats, getCluster, getClusterMetrics, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseSettings, getDeployPreviewBranch, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationHistory, getMigrationJobStatus, getMigrationJobs, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getSchema, getSchemas, getTableColumns, getTableSchema, getTaskStatus, getTasks, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspaceSettings, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, installClusterExtension, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, le, lessEquals, lessThan, lessThanEquals, listClusterBranches, listClusterExtensions, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, moveBranch, 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 };
5511
5435
  //# sourceMappingURL=index.mjs.map