@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/.turbo/turbo-build.log +3 -3
- package/CHANGELOG.md +3 -3
- package/dist/index.cjs +279 -538
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4225 -3926
- package/dist/index.mjs +275 -535
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -39,8 +39,7 @@ function getLens(b64) {
|
|
39
39
|
throw new Error("Invalid string. Length must be a multiple of 4");
|
40
40
|
}
|
41
41
|
let validLen = b64.indexOf("=");
|
42
|
-
if (validLen === -1)
|
43
|
-
validLen = len;
|
42
|
+
if (validLen === -1) validLen = len;
|
44
43
|
const placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
|
45
44
|
return [validLen, placeHoldersLen];
|
46
45
|
}
|
@@ -375,10 +374,8 @@ class Buffer extends Uint8Array {
|
|
375
374
|
break;
|
376
375
|
}
|
377
376
|
}
|
378
|
-
if (x < y)
|
379
|
-
|
380
|
-
if (y < x)
|
381
|
-
return 1;
|
377
|
+
if (x < y) return -1;
|
378
|
+
if (y < x) return 1;
|
382
379
|
return 0;
|
383
380
|
}
|
384
381
|
/**
|
@@ -391,33 +388,21 @@ class Buffer extends Uint8Array {
|
|
391
388
|
* @param sourceEnd The offset within this buffer at which to end copying (exclusive).
|
392
389
|
*/
|
393
390
|
copy(targetBuffer, targetStart, sourceStart, sourceEnd) {
|
394
|
-
if (!Buffer.isBuffer(targetBuffer))
|
395
|
-
|
396
|
-
if (!
|
397
|
-
|
398
|
-
if (
|
399
|
-
|
400
|
-
if (
|
401
|
-
|
402
|
-
if (
|
403
|
-
targetStart = targetBuffer.length;
|
404
|
-
if (!targetStart)
|
405
|
-
targetStart = 0;
|
406
|
-
if (sourceEnd > 0 && sourceEnd < sourceStart)
|
407
|
-
sourceEnd = sourceStart;
|
408
|
-
if (sourceEnd === sourceStart)
|
409
|
-
return 0;
|
410
|
-
if (targetBuffer.length === 0 || this.length === 0)
|
411
|
-
return 0;
|
391
|
+
if (!Buffer.isBuffer(targetBuffer)) throw new TypeError("argument should be a Buffer");
|
392
|
+
if (!sourceStart) sourceStart = 0;
|
393
|
+
if (!targetStart) targetStart = 0;
|
394
|
+
if (!sourceEnd && sourceEnd !== 0) sourceEnd = this.length;
|
395
|
+
if (targetStart >= targetBuffer.length) targetStart = targetBuffer.length;
|
396
|
+
if (!targetStart) targetStart = 0;
|
397
|
+
if (sourceEnd > 0 && sourceEnd < sourceStart) sourceEnd = sourceStart;
|
398
|
+
if (sourceEnd === sourceStart) return 0;
|
399
|
+
if (targetBuffer.length === 0 || this.length === 0) return 0;
|
412
400
|
if (targetStart < 0) {
|
413
401
|
throw new RangeError("targetStart out of bounds");
|
414
402
|
}
|
415
|
-
if (sourceStart < 0 || sourceStart >= this.length)
|
416
|
-
|
417
|
-
if (sourceEnd
|
418
|
-
throw new RangeError("sourceEnd out of bounds");
|
419
|
-
if (sourceEnd > this.length)
|
420
|
-
sourceEnd = this.length;
|
403
|
+
if (sourceStart < 0 || sourceStart >= this.length) throw new RangeError("Index out of range");
|
404
|
+
if (sourceEnd < 0) throw new RangeError("sourceEnd out of bounds");
|
405
|
+
if (sourceEnd > this.length) sourceEnd = this.length;
|
421
406
|
if (targetBuffer.length - targetStart < sourceEnd - sourceStart) {
|
422
407
|
sourceEnd = targetBuffer.length - targetStart + sourceStart;
|
423
408
|
}
|
@@ -1578,8 +1563,7 @@ class Buffer extends Uint8Array {
|
|
1578
1563
|
let c, hi, lo;
|
1579
1564
|
const byteArray = [];
|
1580
1565
|
for (let i = 0; i < str.length; ++i) {
|
1581
|
-
if ((units -= 2) < 0)
|
1582
|
-
break;
|
1566
|
+
if ((units -= 2) < 0) break;
|
1583
1567
|
c = str.charCodeAt(i);
|
1584
1568
|
hi = c >> 8;
|
1585
1569
|
lo = c % 256;
|
@@ -1733,13 +1717,10 @@ class Buffer extends Uint8Array {
|
|
1733
1717
|
let foundIndex = -1;
|
1734
1718
|
for (i = byteOffset; i < arrLength; i++) {
|
1735
1719
|
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
1736
|
-
if (foundIndex === -1)
|
1737
|
-
|
1738
|
-
if (i - foundIndex + 1 === valLength)
|
1739
|
-
return foundIndex * indexSize;
|
1720
|
+
if (foundIndex === -1) foundIndex = i;
|
1721
|
+
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
|
1740
1722
|
} else {
|
1741
|
-
if (foundIndex !== -1)
|
1742
|
-
i -= i - foundIndex;
|
1723
|
+
if (foundIndex !== -1) i -= i - foundIndex;
|
1743
1724
|
foundIndex = -1;
|
1744
1725
|
}
|
1745
1726
|
}
|
@@ -1763,18 +1744,13 @@ class Buffer extends Uint8Array {
|
|
1763
1744
|
return -1;
|
1764
1745
|
}
|
1765
1746
|
static _checkOffset(offset, ext, length) {
|
1766
|
-
if (offset % 1 !== 0 || offset < 0)
|
1767
|
-
|
1768
|
-
if (offset + ext > length)
|
1769
|
-
throw new RangeError("Trying to access beyond buffer length");
|
1747
|
+
if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint");
|
1748
|
+
if (offset + ext > length) throw new RangeError("Trying to access beyond buffer length");
|
1770
1749
|
}
|
1771
1750
|
static _checkInt(buf, value, offset, ext, max, min) {
|
1772
|
-
if (!Buffer.isBuffer(buf))
|
1773
|
-
|
1774
|
-
if (
|
1775
|
-
throw new RangeError('"value" argument is out of bounds');
|
1776
|
-
if (offset + ext > buf.length)
|
1777
|
-
throw new RangeError("Index out of range");
|
1751
|
+
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
|
1752
|
+
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
|
1753
|
+
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
1778
1754
|
}
|
1779
1755
|
static _getEncoding(encoding) {
|
1780
1756
|
let toLowerCase = false;
|
@@ -1824,8 +1800,7 @@ const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
1824
1800
|
function base64clean(str) {
|
1825
1801
|
str = str.split("=")[0];
|
1826
1802
|
str = str.trim().replace(INVALID_BASE64_RE, "");
|
1827
|
-
if (str.length < 2)
|
1828
|
-
return "";
|
1803
|
+
if (str.length < 2) return "";
|
1829
1804
|
while (str.length % 4 !== 0) {
|
1830
1805
|
str = str + "=";
|
1831
1806
|
}
|
@@ -1926,155 +1901,15 @@ function promiseMap(inputValues, mapper) {
|
|
1926
1901
|
return inputValues.reduce(reducer, Promise.resolve([]));
|
1927
1902
|
}
|
1928
1903
|
|
1929
|
-
|
1930
|
-
|
1931
|
-
if (isDefined(process) && isDefined(process.env)) {
|
1932
|
-
return {
|
1933
|
-
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
1934
|
-
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
1935
|
-
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
1936
|
-
deployPreview: process.env.XATA_PREVIEW,
|
1937
|
-
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
1938
|
-
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
1939
|
-
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
1940
|
-
};
|
1941
|
-
}
|
1942
|
-
} catch (err) {
|
1943
|
-
}
|
1944
|
-
try {
|
1945
|
-
if (isObject(Deno) && isObject(Deno.env)) {
|
1946
|
-
return {
|
1947
|
-
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
1948
|
-
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
1949
|
-
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
1950
|
-
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
1951
|
-
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
1952
|
-
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
1953
|
-
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
1954
|
-
};
|
1955
|
-
}
|
1956
|
-
} catch (err) {
|
1957
|
-
}
|
1958
|
-
return {
|
1959
|
-
apiKey: getGlobalApiKey(),
|
1960
|
-
databaseURL: getGlobalDatabaseURL(),
|
1961
|
-
branch: getGlobalBranch(),
|
1962
|
-
deployPreview: void 0,
|
1963
|
-
deployPreviewBranch: void 0,
|
1964
|
-
vercelGitCommitRef: void 0,
|
1965
|
-
vercelGitRepoOwner: void 0
|
1966
|
-
};
|
1967
|
-
}
|
1968
|
-
function getEnableBrowserVariable() {
|
1969
|
-
try {
|
1970
|
-
if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
|
1971
|
-
return process.env.XATA_ENABLE_BROWSER === "true";
|
1972
|
-
}
|
1973
|
-
} catch (err) {
|
1974
|
-
}
|
1975
|
-
try {
|
1976
|
-
if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
|
1977
|
-
return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
|
1978
|
-
}
|
1979
|
-
} catch (err) {
|
1980
|
-
}
|
1981
|
-
try {
|
1982
|
-
return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
|
1983
|
-
} catch (err) {
|
1984
|
-
return void 0;
|
1985
|
-
}
|
1986
|
-
}
|
1987
|
-
function getGlobalApiKey() {
|
1988
|
-
try {
|
1989
|
-
return XATA_API_KEY;
|
1990
|
-
} catch (err) {
|
1991
|
-
return void 0;
|
1992
|
-
}
|
1993
|
-
}
|
1994
|
-
function getGlobalDatabaseURL() {
|
1995
|
-
try {
|
1996
|
-
return XATA_DATABASE_URL;
|
1997
|
-
} catch (err) {
|
1998
|
-
return void 0;
|
1999
|
-
}
|
2000
|
-
}
|
2001
|
-
function getGlobalBranch() {
|
2002
|
-
try {
|
2003
|
-
return XATA_BRANCH;
|
2004
|
-
} catch (err) {
|
2005
|
-
return void 0;
|
2006
|
-
}
|
2007
|
-
}
|
2008
|
-
function getDatabaseURL() {
|
2009
|
-
try {
|
2010
|
-
const { databaseURL } = getEnvironment();
|
2011
|
-
return databaseURL;
|
2012
|
-
} catch (err) {
|
2013
|
-
return void 0;
|
2014
|
-
}
|
2015
|
-
}
|
2016
|
-
function getAPIKey() {
|
2017
|
-
try {
|
2018
|
-
const { apiKey } = getEnvironment();
|
2019
|
-
return apiKey;
|
2020
|
-
} catch (err) {
|
2021
|
-
return void 0;
|
2022
|
-
}
|
2023
|
-
}
|
2024
|
-
function getBranch() {
|
2025
|
-
try {
|
2026
|
-
const { branch } = getEnvironment();
|
2027
|
-
return branch;
|
2028
|
-
} catch (err) {
|
2029
|
-
return void 0;
|
2030
|
-
}
|
2031
|
-
}
|
2032
|
-
function buildPreviewBranchName({ org, branch }) {
|
2033
|
-
return `preview-${org}-${branch}`;
|
2034
|
-
}
|
2035
|
-
function getPreviewBranch() {
|
2036
|
-
try {
|
2037
|
-
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
2038
|
-
if (deployPreviewBranch)
|
2039
|
-
return deployPreviewBranch;
|
2040
|
-
switch (deployPreview) {
|
2041
|
-
case "vercel": {
|
2042
|
-
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
2043
|
-
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
2044
|
-
return void 0;
|
2045
|
-
}
|
2046
|
-
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
2047
|
-
}
|
2048
|
-
}
|
2049
|
-
return void 0;
|
2050
|
-
} catch (err) {
|
2051
|
-
return void 0;
|
2052
|
-
}
|
2053
|
-
}
|
2054
|
-
|
2055
|
-
var __accessCheck$6 = (obj, member, msg) => {
|
2056
|
-
if (!member.has(obj))
|
2057
|
-
throw TypeError("Cannot " + msg);
|
2058
|
-
};
|
2059
|
-
var __privateGet$5 = (obj, member, getter) => {
|
2060
|
-
__accessCheck$6(obj, member, "read from private field");
|
2061
|
-
return getter ? getter.call(obj) : member.get(obj);
|
2062
|
-
};
|
2063
|
-
var __privateAdd$6 = (obj, member, value) => {
|
2064
|
-
if (member.has(obj))
|
2065
|
-
throw TypeError("Cannot add the same private member more than once");
|
2066
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
2067
|
-
};
|
2068
|
-
var __privateSet$4 = (obj, member, value, setter) => {
|
2069
|
-
__accessCheck$6(obj, member, "write to private field");
|
2070
|
-
member.set(obj, value);
|
2071
|
-
return value;
|
1904
|
+
var __typeError$6 = (msg) => {
|
1905
|
+
throw TypeError(msg);
|
2072
1906
|
};
|
2073
|
-
var
|
2074
|
-
|
2075
|
-
|
2076
|
-
|
2077
|
-
var
|
1907
|
+
var __accessCheck$6 = (obj, member, msg) => member.has(obj) || __typeError$6("Cannot " + msg);
|
1908
|
+
var __privateGet$5 = (obj, member, getter) => (__accessCheck$6(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
1909
|
+
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);
|
1910
|
+
var __privateSet$4 = (obj, member, value, setter) => (__accessCheck$6(obj, member, "write to private field"), member.set(obj, value), value);
|
1911
|
+
var __privateMethod$4 = (obj, member, method) => (__accessCheck$6(obj, member, "access private method"), method);
|
1912
|
+
var _fetch, _queue, _concurrency, _ApiRequestPool_instances, enqueue_fn;
|
2078
1913
|
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
2079
1914
|
function getFetchImplementation(userFetch) {
|
2080
1915
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
@@ -2087,10 +1922,10 @@ function getFetchImplementation(userFetch) {
|
|
2087
1922
|
}
|
2088
1923
|
class ApiRequestPool {
|
2089
1924
|
constructor(concurrency = 10) {
|
2090
|
-
__privateAdd$6(this,
|
2091
|
-
__privateAdd$6(this, _fetch
|
2092
|
-
__privateAdd$6(this, _queue
|
2093
|
-
__privateAdd$6(this, _concurrency
|
1925
|
+
__privateAdd$6(this, _ApiRequestPool_instances);
|
1926
|
+
__privateAdd$6(this, _fetch);
|
1927
|
+
__privateAdd$6(this, _queue);
|
1928
|
+
__privateAdd$6(this, _concurrency);
|
2094
1929
|
__privateSet$4(this, _queue, []);
|
2095
1930
|
__privateSet$4(this, _concurrency, concurrency);
|
2096
1931
|
this.running = 0;
|
@@ -2125,7 +1960,7 @@ class ApiRequestPool {
|
|
2125
1960
|
}
|
2126
1961
|
return response;
|
2127
1962
|
};
|
2128
|
-
return __privateMethod$4(this,
|
1963
|
+
return __privateMethod$4(this, _ApiRequestPool_instances, enqueue_fn).call(this, async () => {
|
2129
1964
|
return await runRequest();
|
2130
1965
|
});
|
2131
1966
|
}
|
@@ -2133,7 +1968,7 @@ class ApiRequestPool {
|
|
2133
1968
|
_fetch = new WeakMap();
|
2134
1969
|
_queue = new WeakMap();
|
2135
1970
|
_concurrency = new WeakMap();
|
2136
|
-
|
1971
|
+
_ApiRequestPool_instances = new WeakSet();
|
2137
1972
|
enqueue_fn = function(task) {
|
2138
1973
|
const promise = new Promise((resolve) => __privateGet$5(this, _queue).push(resolve)).finally(() => {
|
2139
1974
|
this.started--;
|
@@ -2416,18 +2251,15 @@ function parseProviderString(provider = "production") {
|
|
2416
2251
|
return provider;
|
2417
2252
|
}
|
2418
2253
|
const [main, workspaces] = provider.split(",");
|
2419
|
-
if (!main || !workspaces)
|
2420
|
-
return null;
|
2254
|
+
if (!main || !workspaces) return null;
|
2421
2255
|
return { main, workspaces };
|
2422
2256
|
}
|
2423
2257
|
function buildProviderString(provider) {
|
2424
|
-
if (isHostProviderAlias(provider))
|
2425
|
-
return provider;
|
2258
|
+
if (isHostProviderAlias(provider)) return provider;
|
2426
2259
|
return `${provider.main},${provider.workspaces}`;
|
2427
2260
|
}
|
2428
2261
|
function parseWorkspacesUrlParts(url) {
|
2429
|
-
if (!isString(url))
|
2430
|
-
return null;
|
2262
|
+
if (!isString(url)) return null;
|
2431
2263
|
const matches = {
|
2432
2264
|
production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh\/db\/([^:]+):?(.*)?/),
|
2433
2265
|
staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev\/db\/([^:]+):?(.*)?/),
|
@@ -2435,16 +2267,14 @@ function parseWorkspacesUrlParts(url) {
|
|
2435
2267
|
local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(?:\d+)\/db\/([^:]+):?(.*)?/)
|
2436
2268
|
};
|
2437
2269
|
const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
|
2438
|
-
if (!isHostProviderAlias(host) || !match)
|
2439
|
-
return null;
|
2270
|
+
if (!isHostProviderAlias(host) || !match) return null;
|
2440
2271
|
return { workspace: match[1], region: match[2], database: match[3], branch: match[4], host };
|
2441
2272
|
}
|
2442
2273
|
|
2443
2274
|
const pool = new ApiRequestPool();
|
2444
2275
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
2445
2276
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
2446
|
-
if (value === void 0 || value === null)
|
2447
|
-
return acc;
|
2277
|
+
if (value === void 0 || value === null) return acc;
|
2448
2278
|
return { ...acc, [key]: value };
|
2449
2279
|
}, {});
|
2450
2280
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
@@ -2492,8 +2322,7 @@ function hostHeader(url) {
|
|
2492
2322
|
return groups?.host ? { Host: groups.host } : {};
|
2493
2323
|
}
|
2494
2324
|
async function parseBody(body, headers) {
|
2495
|
-
if (!isDefined(body))
|
2496
|
-
return void 0;
|
2325
|
+
if (!isDefined(body)) return void 0;
|
2497
2326
|
if (isBlob(body) || typeof body.text === "function") {
|
2498
2327
|
return body;
|
2499
2328
|
}
|
@@ -2572,8 +2401,7 @@ async function fetch$1({
|
|
2572
2401
|
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
2573
2402
|
});
|
2574
2403
|
const message = response.headers?.get("x-xata-message");
|
2575
|
-
if (message)
|
2576
|
-
console.warn(message);
|
2404
|
+
if (message) console.warn(message);
|
2577
2405
|
if (response.status === 204) {
|
2578
2406
|
return {};
|
2579
2407
|
}
|
@@ -2663,6 +2491,24 @@ const applyMigration = (variables, signal) => dataPlaneFetch({
|
|
2663
2491
|
...variables,
|
2664
2492
|
signal
|
2665
2493
|
});
|
2494
|
+
const startMigration = (variables, signal) => dataPlaneFetch({
|
2495
|
+
url: "/db/{dbBranchName}/migrations/start",
|
2496
|
+
method: "post",
|
2497
|
+
...variables,
|
2498
|
+
signal
|
2499
|
+
});
|
2500
|
+
const completeMigration = (variables, signal) => dataPlaneFetch({
|
2501
|
+
url: "/db/{dbBranchName}/migrations/complete",
|
2502
|
+
method: "post",
|
2503
|
+
...variables,
|
2504
|
+
signal
|
2505
|
+
});
|
2506
|
+
const rollbackMigration = (variables, signal) => dataPlaneFetch({
|
2507
|
+
url: "/db/{dbBranchName}/migrations/rollback",
|
2508
|
+
method: "post",
|
2509
|
+
...variables,
|
2510
|
+
signal
|
2511
|
+
});
|
2666
2512
|
const adaptTable = (variables, signal) => dataPlaneFetch({
|
2667
2513
|
url: "/db/{dbBranchName}/migrations/adapt/{tableName}",
|
2668
2514
|
method: "post",
|
@@ -3078,9 +2924,18 @@ const sqlQuery = (variables, signal) => dataPlaneFetch({
|
|
3078
2924
|
...variables,
|
3079
2925
|
signal
|
3080
2926
|
});
|
2927
|
+
const sqlBatchQuery = (variables, signal) => dataPlaneFetch({
|
2928
|
+
url: "/db/{dbBranchName}/sql/batch",
|
2929
|
+
method: "post",
|
2930
|
+
...variables,
|
2931
|
+
signal
|
2932
|
+
});
|
3081
2933
|
const operationsByTag$2 = {
|
3082
2934
|
migrations: {
|
3083
2935
|
applyMigration,
|
2936
|
+
startMigration,
|
2937
|
+
completeMigration,
|
2938
|
+
rollbackMigration,
|
3084
2939
|
adaptTable,
|
3085
2940
|
adaptAllTables,
|
3086
2941
|
getBranchMigrationJobStatus,
|
@@ -3165,7 +3020,7 @@ const operationsByTag$2 = {
|
|
3165
3020
|
summarizeTable,
|
3166
3021
|
aggregateTable
|
3167
3022
|
},
|
3168
|
-
sql: { sqlQuery }
|
3023
|
+
sql: { sqlQuery, sqlBatchQuery }
|
3169
3024
|
};
|
3170
3025
|
|
3171
3026
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
@@ -3475,7 +3330,7 @@ const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
|
3475
3330
|
const buildApiClient = () => class {
|
3476
3331
|
constructor(options = {}) {
|
3477
3332
|
const provider = options.host ?? "production";
|
3478
|
-
const apiKey = options.apiKey
|
3333
|
+
const apiKey = options.apiKey;
|
3479
3334
|
const trace = options.trace ?? defaultTrace;
|
3480
3335
|
const clientID = generateUUID();
|
3481
3336
|
if (!apiKey) {
|
@@ -3542,8 +3397,7 @@ function buildTransformString(transformations) {
|
|
3542
3397
|
).join(",");
|
3543
3398
|
}
|
3544
3399
|
function transformImage(url, ...transformations) {
|
3545
|
-
if (!isDefined(url))
|
3546
|
-
return void 0;
|
3400
|
+
if (!isDefined(url)) return void 0;
|
3547
3401
|
const newTransformations = buildTransformString(transformations);
|
3548
3402
|
const { hostname, pathname, search } = new URL(url);
|
3549
3403
|
const pathParts = pathname.split("/");
|
@@ -3656,8 +3510,7 @@ class XataFile {
|
|
3656
3510
|
}
|
3657
3511
|
}
|
3658
3512
|
const parseInputFileEntry = async (entry) => {
|
3659
|
-
if (!isDefined(entry))
|
3660
|
-
return null;
|
3513
|
+
if (!isDefined(entry)) return null;
|
3661
3514
|
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
|
3662
3515
|
return compactObject({
|
3663
3516
|
id,
|
@@ -3672,24 +3525,19 @@ const parseInputFileEntry = async (entry) => {
|
|
3672
3525
|
};
|
3673
3526
|
|
3674
3527
|
function cleanFilter(filter) {
|
3675
|
-
if (!isDefined(filter))
|
3676
|
-
|
3677
|
-
if (!isObject(filter))
|
3678
|
-
return filter;
|
3528
|
+
if (!isDefined(filter)) return void 0;
|
3529
|
+
if (!isObject(filter)) return filter;
|
3679
3530
|
const values = Object.fromEntries(
|
3680
3531
|
Object.entries(filter).reduce((acc, [key, value]) => {
|
3681
|
-
if (!isDefined(value))
|
3682
|
-
return acc;
|
3532
|
+
if (!isDefined(value)) return acc;
|
3683
3533
|
if (Array.isArray(value)) {
|
3684
3534
|
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
3685
|
-
if (clean.length === 0)
|
3686
|
-
return acc;
|
3535
|
+
if (clean.length === 0) return acc;
|
3687
3536
|
return [...acc, [key, clean]];
|
3688
3537
|
}
|
3689
3538
|
if (isObject(value)) {
|
3690
3539
|
const clean = cleanFilter(value);
|
3691
|
-
if (!isDefined(clean))
|
3692
|
-
return acc;
|
3540
|
+
if (!isDefined(clean)) return acc;
|
3693
3541
|
return [...acc, [key, clean]];
|
3694
3542
|
}
|
3695
3543
|
return [...acc, [key, value]];
|
@@ -3699,10 +3547,8 @@ function cleanFilter(filter) {
|
|
3699
3547
|
}
|
3700
3548
|
|
3701
3549
|
function stringifyJson(value) {
|
3702
|
-
if (!isDefined(value))
|
3703
|
-
|
3704
|
-
if (isString(value))
|
3705
|
-
return value;
|
3550
|
+
if (!isDefined(value)) return value;
|
3551
|
+
if (isString(value)) return value;
|
3706
3552
|
try {
|
3707
3553
|
return JSON.stringify(value);
|
3708
3554
|
} catch (e) {
|
@@ -3717,28 +3563,17 @@ function parseJson(value) {
|
|
3717
3563
|
}
|
3718
3564
|
}
|
3719
3565
|
|
3720
|
-
var
|
3721
|
-
|
3722
|
-
throw TypeError("Cannot " + msg);
|
3723
|
-
};
|
3724
|
-
var __privateGet$4 = (obj, member, getter) => {
|
3725
|
-
__accessCheck$5(obj, member, "read from private field");
|
3726
|
-
return getter ? getter.call(obj) : member.get(obj);
|
3727
|
-
};
|
3728
|
-
var __privateAdd$5 = (obj, member, value) => {
|
3729
|
-
if (member.has(obj))
|
3730
|
-
throw TypeError("Cannot add the same private member more than once");
|
3731
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
3732
|
-
};
|
3733
|
-
var __privateSet$3 = (obj, member, value, setter) => {
|
3734
|
-
__accessCheck$5(obj, member, "write to private field");
|
3735
|
-
member.set(obj, value);
|
3736
|
-
return value;
|
3566
|
+
var __typeError$5 = (msg) => {
|
3567
|
+
throw TypeError(msg);
|
3737
3568
|
};
|
3569
|
+
var __accessCheck$5 = (obj, member, msg) => member.has(obj) || __typeError$5("Cannot " + msg);
|
3570
|
+
var __privateGet$4 = (obj, member, getter) => (__accessCheck$5(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
3571
|
+
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);
|
3572
|
+
var __privateSet$3 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value);
|
3738
3573
|
var _query, _page;
|
3739
3574
|
class Page {
|
3740
3575
|
constructor(query, meta, records = []) {
|
3741
|
-
__privateAdd$5(this, _query
|
3576
|
+
__privateAdd$5(this, _query);
|
3742
3577
|
__privateSet$3(this, _query, query);
|
3743
3578
|
this.meta = meta;
|
3744
3579
|
this.records = new PageRecordArray(this, records);
|
@@ -3825,7 +3660,7 @@ class RecordArray extends Array {
|
|
3825
3660
|
const _PageRecordArray = class _PageRecordArray extends Array {
|
3826
3661
|
constructor(...args) {
|
3827
3662
|
super(..._PageRecordArray.parseConstructorParams(...args));
|
3828
|
-
__privateAdd$5(this, _page
|
3663
|
+
__privateAdd$5(this, _page);
|
3829
3664
|
__privateSet$3(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
3830
3665
|
}
|
3831
3666
|
static parseConstructorParams(...args) {
|
@@ -3896,34 +3731,20 @@ const _PageRecordArray = class _PageRecordArray extends Array {
|
|
3896
3731
|
_page = new WeakMap();
|
3897
3732
|
let PageRecordArray = _PageRecordArray;
|
3898
3733
|
|
3899
|
-
var
|
3900
|
-
|
3901
|
-
throw TypeError("Cannot " + msg);
|
3902
|
-
};
|
3903
|
-
var __privateGet$3 = (obj, member, getter) => {
|
3904
|
-
__accessCheck$4(obj, member, "read from private field");
|
3905
|
-
return getter ? getter.call(obj) : member.get(obj);
|
3906
|
-
};
|
3907
|
-
var __privateAdd$4 = (obj, member, value) => {
|
3908
|
-
if (member.has(obj))
|
3909
|
-
throw TypeError("Cannot add the same private member more than once");
|
3910
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
3734
|
+
var __typeError$4 = (msg) => {
|
3735
|
+
throw TypeError(msg);
|
3911
3736
|
};
|
3912
|
-
var
|
3913
|
-
|
3914
|
-
|
3915
|
-
|
3916
|
-
|
3917
|
-
var
|
3918
|
-
__accessCheck$4(obj, member, "access private method");
|
3919
|
-
return method;
|
3920
|
-
};
|
3921
|
-
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
3737
|
+
var __accessCheck$4 = (obj, member, msg) => member.has(obj) || __typeError$4("Cannot " + msg);
|
3738
|
+
var __privateGet$3 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
3739
|
+
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);
|
3740
|
+
var __privateSet$2 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value);
|
3741
|
+
var __privateMethod$3 = (obj, member, method) => (__accessCheck$4(obj, member, "access private method"), method);
|
3742
|
+
var _table$1, _repository, _data, _Query_instances, cleanFilterConstraint_fn;
|
3922
3743
|
const _Query = class _Query {
|
3923
3744
|
constructor(repository, table, data, rawParent) {
|
3924
|
-
__privateAdd$4(this,
|
3925
|
-
__privateAdd$4(this, _table$1
|
3926
|
-
__privateAdd$4(this, _repository
|
3745
|
+
__privateAdd$4(this, _Query_instances);
|
3746
|
+
__privateAdd$4(this, _table$1);
|
3747
|
+
__privateAdd$4(this, _repository);
|
3927
3748
|
__privateAdd$4(this, _data, { filter: {} });
|
3928
3749
|
// Implements pagination
|
3929
3750
|
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
@@ -4001,12 +3822,12 @@ const _Query = class _Query {
|
|
4001
3822
|
filter(a, b) {
|
4002
3823
|
if (arguments.length === 1) {
|
4003
3824
|
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
4004
|
-
[column]: __privateMethod$3(this,
|
3825
|
+
[column]: __privateMethod$3(this, _Query_instances, cleanFilterConstraint_fn).call(this, column, constraint)
|
4005
3826
|
}));
|
4006
3827
|
const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat(constraints));
|
4007
3828
|
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
|
4008
3829
|
} else {
|
4009
|
-
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this,
|
3830
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _Query_instances, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
4010
3831
|
const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat(constraints));
|
4011
3832
|
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
|
4012
3833
|
}
|
@@ -4085,8 +3906,7 @@ const _Query = class _Query {
|
|
4085
3906
|
}
|
4086
3907
|
async getFirstOrThrow(options = {}) {
|
4087
3908
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
4088
|
-
if (records[0] === void 0)
|
4089
|
-
throw new Error("No results found.");
|
3909
|
+
if (records[0] === void 0) throw new Error("No results found.");
|
4090
3910
|
return records[0];
|
4091
3911
|
}
|
4092
3912
|
async summarize(params = {}) {
|
@@ -4141,7 +3961,7 @@ const _Query = class _Query {
|
|
4141
3961
|
_table$1 = new WeakMap();
|
4142
3962
|
_repository = new WeakMap();
|
4143
3963
|
_data = new WeakMap();
|
4144
|
-
|
3964
|
+
_Query_instances = new WeakSet();
|
4145
3965
|
cleanFilterConstraint_fn = function(column, value) {
|
4146
3966
|
const columnType = __privateGet$3(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
4147
3967
|
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
@@ -4202,8 +4022,7 @@ function isSortFilterString(value) {
|
|
4202
4022
|
}
|
4203
4023
|
function isSortFilterBase(filter) {
|
4204
4024
|
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
4205
|
-
if (key === "*")
|
4206
|
-
return value === "random";
|
4025
|
+
if (key === "*") return value === "random";
|
4207
4026
|
return value === "asc" || value === "desc";
|
4208
4027
|
});
|
4209
4028
|
}
|
@@ -4224,29 +4043,15 @@ function buildSortFilter(filter) {
|
|
4224
4043
|
}
|
4225
4044
|
}
|
4226
4045
|
|
4227
|
-
var
|
4228
|
-
|
4229
|
-
throw TypeError("Cannot " + msg);
|
4230
|
-
};
|
4231
|
-
var __privateGet$2 = (obj, member, getter) => {
|
4232
|
-
__accessCheck$3(obj, member, "read from private field");
|
4233
|
-
return getter ? getter.call(obj) : member.get(obj);
|
4234
|
-
};
|
4235
|
-
var __privateAdd$3 = (obj, member, value) => {
|
4236
|
-
if (member.has(obj))
|
4237
|
-
throw TypeError("Cannot add the same private member more than once");
|
4238
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
4046
|
+
var __typeError$3 = (msg) => {
|
4047
|
+
throw TypeError(msg);
|
4239
4048
|
};
|
4240
|
-
var
|
4241
|
-
|
4242
|
-
|
4243
|
-
|
4244
|
-
|
4245
|
-
var
|
4246
|
-
__accessCheck$3(obj, member, "access private method");
|
4247
|
-
return method;
|
4248
|
-
};
|
4249
|
-
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;
|
4049
|
+
var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
|
4050
|
+
var __privateGet$2 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
4051
|
+
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);
|
4052
|
+
var __privateSet$1 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value);
|
4053
|
+
var __privateMethod$2 = (obj, member, method) => (__accessCheck$3(obj, member, "access private method"), method);
|
4054
|
+
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;
|
4250
4055
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
4251
4056
|
class Repository extends Query {
|
4252
4057
|
}
|
@@ -4257,21 +4062,12 @@ class RestRepository extends Query {
|
|
4257
4062
|
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
4258
4063
|
{}
|
4259
4064
|
);
|
4260
|
-
__privateAdd$3(this,
|
4261
|
-
__privateAdd$3(this,
|
4262
|
-
__privateAdd$3(this,
|
4263
|
-
__privateAdd$3(this,
|
4264
|
-
__privateAdd$3(this,
|
4265
|
-
__privateAdd$3(this,
|
4266
|
-
__privateAdd$3(this, _deleteRecord);
|
4267
|
-
__privateAdd$3(this, _deleteRecords);
|
4268
|
-
__privateAdd$3(this, _getSchemaTables);
|
4269
|
-
__privateAdd$3(this, _transformObjectToApi);
|
4270
|
-
__privateAdd$3(this, _table, void 0);
|
4271
|
-
__privateAdd$3(this, _getFetchProps, void 0);
|
4272
|
-
__privateAdd$3(this, _db, void 0);
|
4273
|
-
__privateAdd$3(this, _schemaTables, void 0);
|
4274
|
-
__privateAdd$3(this, _trace, void 0);
|
4065
|
+
__privateAdd$3(this, _RestRepository_instances);
|
4066
|
+
__privateAdd$3(this, _table);
|
4067
|
+
__privateAdd$3(this, _getFetchProps);
|
4068
|
+
__privateAdd$3(this, _db);
|
4069
|
+
__privateAdd$3(this, _schemaTables);
|
4070
|
+
__privateAdd$3(this, _trace);
|
4275
4071
|
__privateSet$1(this, _table, options.table);
|
4276
4072
|
__privateSet$1(this, _db, options.db);
|
4277
4073
|
__privateSet$1(this, _schemaTables, options.schemaTables);
|
@@ -4290,31 +4086,28 @@ class RestRepository extends Query {
|
|
4290
4086
|
return __privateGet$2(this, _trace).call(this, "create", async () => {
|
4291
4087
|
const ifVersion = parseIfVersion(b, c, d);
|
4292
4088
|
if (Array.isArray(a)) {
|
4293
|
-
if (a.length === 0)
|
4294
|
-
|
4295
|
-
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
4089
|
+
if (a.length === 0) return [];
|
4090
|
+
const ids = await __privateMethod$2(this, _RestRepository_instances, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
4296
4091
|
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
4297
4092
|
const result = await this.read(ids, columns);
|
4298
4093
|
return result;
|
4299
4094
|
}
|
4300
4095
|
if (isString(a) && isObject(b)) {
|
4301
|
-
if (a === "")
|
4302
|
-
throw new Error("The id can't be empty");
|
4096
|
+
if (a === "") throw new Error("The id can't be empty");
|
4303
4097
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
4304
|
-
return await __privateMethod$2(this,
|
4098
|
+
return await __privateMethod$2(this, _RestRepository_instances, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
4305
4099
|
}
|
4306
4100
|
if (isObject(a) && isString(a.xata_id)) {
|
4307
|
-
if (a.xata_id === "")
|
4308
|
-
throw new Error("The id can't be empty");
|
4101
|
+
if (a.xata_id === "") throw new Error("The id can't be empty");
|
4309
4102
|
const columns = isValidSelectableColumns(b) ? b : void 0;
|
4310
|
-
return await __privateMethod$2(this,
|
4103
|
+
return await __privateMethod$2(this, _RestRepository_instances, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
|
4311
4104
|
createOnly: true,
|
4312
4105
|
ifVersion
|
4313
4106
|
});
|
4314
4107
|
}
|
4315
4108
|
if (isObject(a)) {
|
4316
4109
|
const columns = isValidSelectableColumns(b) ? b : void 0;
|
4317
|
-
return __privateMethod$2(this,
|
4110
|
+
return __privateMethod$2(this, _RestRepository_instances, insertRecordWithoutId_fn).call(this, a, columns);
|
4318
4111
|
}
|
4319
4112
|
throw new Error("Invalid arguments for create method");
|
4320
4113
|
});
|
@@ -4323,8 +4116,7 @@ class RestRepository extends Query {
|
|
4323
4116
|
return __privateGet$2(this, _trace).call(this, "read", async () => {
|
4324
4117
|
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
4325
4118
|
if (Array.isArray(a)) {
|
4326
|
-
if (a.length === 0)
|
4327
|
-
return [];
|
4119
|
+
if (a.length === 0) return [];
|
4328
4120
|
const ids = a.map((item) => extractId(item));
|
4329
4121
|
const finalObjects = await this.getAll({ filter: { xata_id: { $any: compact(ids) } }, columns });
|
4330
4122
|
const dictionary = finalObjects.reduce((acc, object) => {
|
@@ -4347,7 +4139,7 @@ class RestRepository extends Query {
|
|
4347
4139
|
queryParams: { columns },
|
4348
4140
|
...__privateGet$2(this, _getFetchProps).call(this)
|
4349
4141
|
});
|
4350
|
-
const schemaTables = await __privateMethod$2(this,
|
4142
|
+
const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
|
4351
4143
|
return initObject(
|
4352
4144
|
__privateGet$2(this, _db),
|
4353
4145
|
schemaTables,
|
@@ -4388,11 +4180,10 @@ class RestRepository extends Query {
|
|
4388
4180
|
return __privateGet$2(this, _trace).call(this, "update", async () => {
|
4389
4181
|
const ifVersion = parseIfVersion(b, c, d);
|
4390
4182
|
if (Array.isArray(a)) {
|
4391
|
-
if (a.length === 0)
|
4392
|
-
return [];
|
4183
|
+
if (a.length === 0) return [];
|
4393
4184
|
const existing = await this.read(a, ["xata_id"]);
|
4394
4185
|
const updates = a.filter((_item, index) => existing[index] !== null);
|
4395
|
-
await __privateMethod$2(this,
|
4186
|
+
await __privateMethod$2(this, _RestRepository_instances, updateRecords_fn).call(this, updates, {
|
4396
4187
|
ifVersion,
|
4397
4188
|
upsert: false
|
4398
4189
|
});
|
@@ -4403,15 +4194,14 @@ class RestRepository extends Query {
|
|
4403
4194
|
try {
|
4404
4195
|
if (isString(a) && isObject(b)) {
|
4405
4196
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
4406
|
-
return await __privateMethod$2(this,
|
4197
|
+
return await __privateMethod$2(this, _RestRepository_instances, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
4407
4198
|
}
|
4408
4199
|
if (isObject(a) && isString(a.xata_id)) {
|
4409
4200
|
const columns = isValidSelectableColumns(b) ? b : void 0;
|
4410
|
-
return await __privateMethod$2(this,
|
4201
|
+
return await __privateMethod$2(this, _RestRepository_instances, updateRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
|
4411
4202
|
}
|
4412
4203
|
} catch (error) {
|
4413
|
-
if (error.status === 422)
|
4414
|
-
return null;
|
4204
|
+
if (error.status === 422) return null;
|
4415
4205
|
throw error;
|
4416
4206
|
}
|
4417
4207
|
throw new Error("Invalid arguments for update method");
|
@@ -4440,9 +4230,8 @@ class RestRepository extends Query {
|
|
4440
4230
|
return __privateGet$2(this, _trace).call(this, "createOrUpdate", async () => {
|
4441
4231
|
const ifVersion = parseIfVersion(b, c, d);
|
4442
4232
|
if (Array.isArray(a)) {
|
4443
|
-
if (a.length === 0)
|
4444
|
-
|
4445
|
-
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
|
4233
|
+
if (a.length === 0) return [];
|
4234
|
+
await __privateMethod$2(this, _RestRepository_instances, updateRecords_fn).call(this, a, {
|
4446
4235
|
ifVersion,
|
4447
4236
|
upsert: true
|
4448
4237
|
});
|
@@ -4451,16 +4240,14 @@ class RestRepository extends Query {
|
|
4451
4240
|
return result;
|
4452
4241
|
}
|
4453
4242
|
if (isString(a) && isObject(b)) {
|
4454
|
-
if (a === "")
|
4455
|
-
throw new Error("The id can't be empty");
|
4243
|
+
if (a === "") throw new Error("The id can't be empty");
|
4456
4244
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
4457
|
-
return await __privateMethod$2(this,
|
4245
|
+
return await __privateMethod$2(this, _RestRepository_instances, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
4458
4246
|
}
|
4459
4247
|
if (isObject(a) && isString(a.xata_id)) {
|
4460
|
-
if (a.xata_id === "")
|
4461
|
-
throw new Error("The id can't be empty");
|
4248
|
+
if (a.xata_id === "") throw new Error("The id can't be empty");
|
4462
4249
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
4463
|
-
return await __privateMethod$2(this,
|
4250
|
+
return await __privateMethod$2(this, _RestRepository_instances, upsertRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
|
4464
4251
|
}
|
4465
4252
|
if (!isDefined(a) && isObject(b)) {
|
4466
4253
|
return await this.create(b, c);
|
@@ -4475,24 +4262,21 @@ class RestRepository extends Query {
|
|
4475
4262
|
return __privateGet$2(this, _trace).call(this, "createOrReplace", async () => {
|
4476
4263
|
const ifVersion = parseIfVersion(b, c, d);
|
4477
4264
|
if (Array.isArray(a)) {
|
4478
|
-
if (a.length === 0)
|
4479
|
-
|
4480
|
-
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
4265
|
+
if (a.length === 0) return [];
|
4266
|
+
const ids = await __privateMethod$2(this, _RestRepository_instances, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
4481
4267
|
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
4482
4268
|
const result = await this.read(ids, columns);
|
4483
4269
|
return result;
|
4484
4270
|
}
|
4485
4271
|
if (isString(a) && isObject(b)) {
|
4486
|
-
if (a === "")
|
4487
|
-
throw new Error("The id can't be empty");
|
4272
|
+
if (a === "") throw new Error("The id can't be empty");
|
4488
4273
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
4489
|
-
return await __privateMethod$2(this,
|
4274
|
+
return await __privateMethod$2(this, _RestRepository_instances, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
4490
4275
|
}
|
4491
4276
|
if (isObject(a) && isString(a.xata_id)) {
|
4492
|
-
if (a.xata_id === "")
|
4493
|
-
throw new Error("The id can't be empty");
|
4277
|
+
if (a.xata_id === "") throw new Error("The id can't be empty");
|
4494
4278
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
4495
|
-
return await __privateMethod$2(this,
|
4279
|
+
return await __privateMethod$2(this, _RestRepository_instances, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
|
4496
4280
|
createOnly: false,
|
4497
4281
|
ifVersion
|
4498
4282
|
});
|
@@ -4509,25 +4293,22 @@ class RestRepository extends Query {
|
|
4509
4293
|
async delete(a, b) {
|
4510
4294
|
return __privateGet$2(this, _trace).call(this, "delete", async () => {
|
4511
4295
|
if (Array.isArray(a)) {
|
4512
|
-
if (a.length === 0)
|
4513
|
-
return [];
|
4296
|
+
if (a.length === 0) return [];
|
4514
4297
|
const ids = a.map((o) => {
|
4515
|
-
if (isString(o))
|
4516
|
-
|
4517
|
-
if (isString(o.xata_id))
|
4518
|
-
return o.xata_id;
|
4298
|
+
if (isString(o)) return o;
|
4299
|
+
if (isString(o.xata_id)) return o.xata_id;
|
4519
4300
|
throw new Error("Invalid arguments for delete method");
|
4520
4301
|
});
|
4521
4302
|
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
4522
4303
|
const result = await this.read(a, columns);
|
4523
|
-
await __privateMethod$2(this,
|
4304
|
+
await __privateMethod$2(this, _RestRepository_instances, deleteRecords_fn).call(this, ids);
|
4524
4305
|
return result;
|
4525
4306
|
}
|
4526
4307
|
if (isString(a)) {
|
4527
|
-
return __privateMethod$2(this,
|
4308
|
+
return __privateMethod$2(this, _RestRepository_instances, deleteRecord_fn).call(this, a, b);
|
4528
4309
|
}
|
4529
4310
|
if (isObject(a) && isString(a.xata_id)) {
|
4530
|
-
return __privateMethod$2(this,
|
4311
|
+
return __privateMethod$2(this, _RestRepository_instances, deleteRecord_fn).call(this, a.xata_id, b);
|
4531
4312
|
}
|
4532
4313
|
throw new Error("Invalid arguments for delete method");
|
4533
4314
|
});
|
@@ -4571,7 +4352,7 @@ class RestRepository extends Query {
|
|
4571
4352
|
},
|
4572
4353
|
...__privateGet$2(this, _getFetchProps).call(this)
|
4573
4354
|
});
|
4574
|
-
const schemaTables = await __privateMethod$2(this,
|
4355
|
+
const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
|
4575
4356
|
return {
|
4576
4357
|
records: records.map((item) => initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), item, ["*"])),
|
4577
4358
|
totalCount
|
@@ -4596,7 +4377,7 @@ class RestRepository extends Query {
|
|
4596
4377
|
},
|
4597
4378
|
...__privateGet$2(this, _getFetchProps).call(this)
|
4598
4379
|
});
|
4599
|
-
const schemaTables = await __privateMethod$2(this,
|
4380
|
+
const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
|
4600
4381
|
return {
|
4601
4382
|
records: records.map((item) => initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), item, ["*"])),
|
4602
4383
|
totalCount
|
@@ -4638,7 +4419,7 @@ class RestRepository extends Query {
|
|
4638
4419
|
fetchOptions: data.fetchOptions,
|
4639
4420
|
...__privateGet$2(this, _getFetchProps).call(this)
|
4640
4421
|
});
|
4641
|
-
const schemaTables = await __privateMethod$2(this,
|
4422
|
+
const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
|
4642
4423
|
const records = objects.map(
|
4643
4424
|
(record) => initObject(
|
4644
4425
|
__privateGet$2(this, _db),
|
@@ -4672,7 +4453,7 @@ class RestRepository extends Query {
|
|
4672
4453
|
},
|
4673
4454
|
...__privateGet$2(this, _getFetchProps).call(this)
|
4674
4455
|
});
|
4675
|
-
const schemaTables = await __privateMethod$2(this,
|
4456
|
+
const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
|
4676
4457
|
return {
|
4677
4458
|
...result,
|
4678
4459
|
summaries: result.summaries.map(
|
@@ -4720,9 +4501,9 @@ _getFetchProps = new WeakMap();
|
|
4720
4501
|
_db = new WeakMap();
|
4721
4502
|
_schemaTables = new WeakMap();
|
4722
4503
|
_trace = new WeakMap();
|
4723
|
-
|
4504
|
+
_RestRepository_instances = new WeakSet();
|
4724
4505
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
4725
|
-
const record = await __privateMethod$2(this,
|
4506
|
+
const record = await __privateMethod$2(this, _RestRepository_instances, transformObjectToApi_fn).call(this, object);
|
4726
4507
|
const response = await insertRecord({
|
4727
4508
|
pathParams: {
|
4728
4509
|
workspace: "{workspaceId}",
|
@@ -4734,14 +4515,12 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
4734
4515
|
body: record,
|
4735
4516
|
...__privateGet$2(this, _getFetchProps).call(this)
|
4736
4517
|
});
|
4737
|
-
const schemaTables = await __privateMethod$2(this,
|
4518
|
+
const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
|
4738
4519
|
return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
|
4739
4520
|
};
|
4740
|
-
_insertRecordWithId = new WeakSet();
|
4741
4521
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
4742
|
-
if (!recordId)
|
4743
|
-
|
4744
|
-
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
4522
|
+
if (!recordId) return null;
|
4523
|
+
const record = await __privateMethod$2(this, _RestRepository_instances, transformObjectToApi_fn).call(this, object);
|
4745
4524
|
const response = await insertRecordWithID({
|
4746
4525
|
pathParams: {
|
4747
4526
|
workspace: "{workspaceId}",
|
@@ -4754,13 +4533,12 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
4754
4533
|
queryParams: { createOnly, columns, ifVersion },
|
4755
4534
|
...__privateGet$2(this, _getFetchProps).call(this)
|
4756
4535
|
});
|
4757
|
-
const schemaTables = await __privateMethod$2(this,
|
4536
|
+
const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
|
4758
4537
|
return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
|
4759
4538
|
};
|
4760
|
-
_insertRecords = new WeakSet();
|
4761
4539
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
4762
4540
|
const operations = await promiseMap(objects, async (object) => {
|
4763
|
-
const record = await __privateMethod$2(this,
|
4541
|
+
const record = await __privateMethod$2(this, _RestRepository_instances, transformObjectToApi_fn).call(this, object);
|
4764
4542
|
return { insert: { table: __privateGet$2(this, _table), record, createOnly, ifVersion } };
|
4765
4543
|
});
|
4766
4544
|
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
@@ -4785,11 +4563,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
4785
4563
|
}
|
4786
4564
|
return ids;
|
4787
4565
|
};
|
4788
|
-
_updateRecordWithID = new WeakSet();
|
4789
4566
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
4790
|
-
if (!recordId)
|
4791
|
-
|
4792
|
-
const { xata_id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
4567
|
+
if (!recordId) return null;
|
4568
|
+
const { xata_id: _id, ...record } = await __privateMethod$2(this, _RestRepository_instances, transformObjectToApi_fn).call(this, object);
|
4793
4569
|
try {
|
4794
4570
|
const response = await updateRecordWithID({
|
4795
4571
|
pathParams: {
|
@@ -4803,7 +4579,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
4803
4579
|
body: record,
|
4804
4580
|
...__privateGet$2(this, _getFetchProps).call(this)
|
4805
4581
|
});
|
4806
|
-
const schemaTables = await __privateMethod$2(this,
|
4582
|
+
const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
|
4807
4583
|
return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
|
4808
4584
|
} catch (e) {
|
4809
4585
|
if (isObject(e) && e.status === 404) {
|
@@ -4812,10 +4588,9 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
4812
4588
|
throw e;
|
4813
4589
|
}
|
4814
4590
|
};
|
4815
|
-
_updateRecords = new WeakSet();
|
4816
4591
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
4817
4592
|
const operations = await promiseMap(objects, async ({ xata_id, ...object }) => {
|
4818
|
-
const fields = await __privateMethod$2(this,
|
4593
|
+
const fields = await __privateMethod$2(this, _RestRepository_instances, transformObjectToApi_fn).call(this, object);
|
4819
4594
|
return { update: { table: __privateGet$2(this, _table), id: xata_id, ifVersion, upsert, fields } };
|
4820
4595
|
});
|
4821
4596
|
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
@@ -4840,10 +4615,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
4840
4615
|
}
|
4841
4616
|
return ids;
|
4842
4617
|
};
|
4843
|
-
_upsertRecordWithID = new WeakSet();
|
4844
4618
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
4845
|
-
if (!recordId)
|
4846
|
-
return null;
|
4619
|
+
if (!recordId) return null;
|
4847
4620
|
const response = await upsertRecordWithID({
|
4848
4621
|
pathParams: {
|
4849
4622
|
workspace: "{workspaceId}",
|
@@ -4856,13 +4629,11 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
4856
4629
|
body: object,
|
4857
4630
|
...__privateGet$2(this, _getFetchProps).call(this)
|
4858
4631
|
});
|
4859
|
-
const schemaTables = await __privateMethod$2(this,
|
4632
|
+
const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
|
4860
4633
|
return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
|
4861
4634
|
};
|
4862
|
-
_deleteRecord = new WeakSet();
|
4863
4635
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
4864
|
-
if (!recordId)
|
4865
|
-
return null;
|
4636
|
+
if (!recordId) return null;
|
4866
4637
|
try {
|
4867
4638
|
const response = await deleteRecord({
|
4868
4639
|
pathParams: {
|
@@ -4875,7 +4646,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
4875
4646
|
queryParams: { columns },
|
4876
4647
|
...__privateGet$2(this, _getFetchProps).call(this)
|
4877
4648
|
});
|
4878
|
-
const schemaTables = await __privateMethod$2(this,
|
4649
|
+
const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
|
4879
4650
|
return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
|
4880
4651
|
} catch (e) {
|
4881
4652
|
if (isObject(e) && e.status === 404) {
|
@@ -4884,7 +4655,6 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
4884
4655
|
throw e;
|
4885
4656
|
}
|
4886
4657
|
};
|
4887
|
-
_deleteRecords = new WeakSet();
|
4888
4658
|
deleteRecords_fn = async function(recordIds) {
|
4889
4659
|
const chunkedOperations = chunk(
|
4890
4660
|
compact(recordIds).map((id) => ({ delete: { table: __privateGet$2(this, _table), id } })),
|
@@ -4902,10 +4672,8 @@ deleteRecords_fn = async function(recordIds) {
|
|
4902
4672
|
});
|
4903
4673
|
}
|
4904
4674
|
};
|
4905
|
-
_getSchemaTables = new WeakSet();
|
4906
4675
|
getSchemaTables_fn = async function() {
|
4907
|
-
if (__privateGet$2(this, _schemaTables))
|
4908
|
-
return __privateGet$2(this, _schemaTables);
|
4676
|
+
if (__privateGet$2(this, _schemaTables)) return __privateGet$2(this, _schemaTables);
|
4909
4677
|
const { schema } = await getBranchDetails({
|
4910
4678
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4911
4679
|
...__privateGet$2(this, _getFetchProps).call(this)
|
@@ -4913,16 +4681,13 @@ getSchemaTables_fn = async function() {
|
|
4913
4681
|
__privateSet$1(this, _schemaTables, schema.tables);
|
4914
4682
|
return schema.tables;
|
4915
4683
|
};
|
4916
|
-
_transformObjectToApi = new WeakSet();
|
4917
4684
|
transformObjectToApi_fn = async function(object) {
|
4918
|
-
const schemaTables = await __privateMethod$2(this,
|
4685
|
+
const schemaTables = await __privateMethod$2(this, _RestRepository_instances, getSchemaTables_fn).call(this);
|
4919
4686
|
const schema = schemaTables.find((table) => table.name === __privateGet$2(this, _table));
|
4920
|
-
if (!schema)
|
4921
|
-
throw new Error(`Table ${__privateGet$2(this, _table)} not found in schema`);
|
4687
|
+
if (!schema) throw new Error(`Table ${__privateGet$2(this, _table)} not found in schema`);
|
4922
4688
|
const result = {};
|
4923
4689
|
for (const [key, value] of Object.entries(object)) {
|
4924
|
-
if (["xata_version", "xata_createdat", "xata_updatedat"].includes(key))
|
4925
|
-
continue;
|
4690
|
+
if (["xata_version", "xata_createdat", "xata_updatedat"].includes(key)) continue;
|
4926
4691
|
const type = schema.columns.find((column) => column.name === key)?.type;
|
4927
4692
|
switch (type) {
|
4928
4693
|
case "link": {
|
@@ -4952,11 +4717,9 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4952
4717
|
const data = {};
|
4953
4718
|
Object.assign(data, { ...object });
|
4954
4719
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
4955
|
-
if (!columns)
|
4956
|
-
console.error(`Table ${table} not found in schema`);
|
4720
|
+
if (!columns) console.error(`Table ${table} not found in schema`);
|
4957
4721
|
for (const column of columns ?? []) {
|
4958
|
-
if (!isValidColumn(selectedColumns, column))
|
4959
|
-
continue;
|
4722
|
+
if (!isValidColumn(selectedColumns, column)) continue;
|
4960
4723
|
const value = data[column.name];
|
4961
4724
|
switch (column.type) {
|
4962
4725
|
case "datetime": {
|
@@ -5042,15 +4805,12 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
5042
4805
|
return record;
|
5043
4806
|
};
|
5044
4807
|
function extractId(value) {
|
5045
|
-
if (isString(value))
|
5046
|
-
|
5047
|
-
if (isObject(value) && isString(value.xata_id))
|
5048
|
-
return value.xata_id;
|
4808
|
+
if (isString(value)) return value;
|
4809
|
+
if (isObject(value) && isString(value.xata_id)) return value.xata_id;
|
5049
4810
|
return void 0;
|
5050
4811
|
}
|
5051
4812
|
function isValidColumn(columns, column) {
|
5052
|
-
if (columns.includes("*"))
|
5053
|
-
return true;
|
4813
|
+
if (columns.includes("*")) return true;
|
5054
4814
|
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
5055
4815
|
}
|
5056
4816
|
function parseIfVersion(...args) {
|
@@ -5090,19 +4850,12 @@ const includesAll = (value) => ({ $includesAll: value });
|
|
5090
4850
|
const includesNone = (value) => ({ $includesNone: value });
|
5091
4851
|
const includesAny = (value) => ({ $includesAny: value });
|
5092
4852
|
|
5093
|
-
var
|
5094
|
-
|
5095
|
-
throw TypeError("Cannot " + msg);
|
5096
|
-
};
|
5097
|
-
var __privateGet$1 = (obj, member, getter) => {
|
5098
|
-
__accessCheck$2(obj, member, "read from private field");
|
5099
|
-
return getter ? getter.call(obj) : member.get(obj);
|
5100
|
-
};
|
5101
|
-
var __privateAdd$2 = (obj, member, value) => {
|
5102
|
-
if (member.has(obj))
|
5103
|
-
throw TypeError("Cannot add the same private member more than once");
|
5104
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
4853
|
+
var __typeError$2 = (msg) => {
|
4854
|
+
throw TypeError(msg);
|
5105
4855
|
};
|
4856
|
+
var __accessCheck$2 = (obj, member, msg) => member.has(obj) || __typeError$2("Cannot " + msg);
|
4857
|
+
var __privateGet$1 = (obj, member, getter) => (__accessCheck$2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
4858
|
+
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);
|
5106
4859
|
var _tables;
|
5107
4860
|
class SchemaPlugin extends XataPlugin {
|
5108
4861
|
constructor() {
|
@@ -5114,8 +4867,7 @@ class SchemaPlugin extends XataPlugin {
|
|
5114
4867
|
{},
|
5115
4868
|
{
|
5116
4869
|
get: (_target, table) => {
|
5117
|
-
if (!isString(table))
|
5118
|
-
throw new Error("Invalid table name");
|
4870
|
+
if (!isString(table)) throw new Error("Invalid table name");
|
5119
4871
|
if (__privateGet$1(this, _tables)[table] === void 0) {
|
5120
4872
|
__privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: pluginOptions.tables });
|
5121
4873
|
}
|
@@ -5206,30 +4958,23 @@ function getContentType(file) {
|
|
5206
4958
|
return "application/octet-stream";
|
5207
4959
|
}
|
5208
4960
|
|
5209
|
-
var
|
5210
|
-
|
5211
|
-
throw TypeError("Cannot " + msg);
|
5212
|
-
};
|
5213
|
-
var __privateAdd$1 = (obj, member, value) => {
|
5214
|
-
if (member.has(obj))
|
5215
|
-
throw TypeError("Cannot add the same private member more than once");
|
5216
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
4961
|
+
var __typeError$1 = (msg) => {
|
4962
|
+
throw TypeError(msg);
|
5217
4963
|
};
|
5218
|
-
var
|
5219
|
-
|
5220
|
-
|
5221
|
-
|
5222
|
-
var _search, search_fn;
|
4964
|
+
var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
|
4965
|
+
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);
|
4966
|
+
var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
|
4967
|
+
var _SearchPlugin_instances, search_fn;
|
5223
4968
|
class SearchPlugin extends XataPlugin {
|
5224
4969
|
constructor(db) {
|
5225
4970
|
super();
|
5226
4971
|
this.db = db;
|
5227
|
-
__privateAdd$1(this,
|
4972
|
+
__privateAdd$1(this, _SearchPlugin_instances);
|
5228
4973
|
}
|
5229
4974
|
build(pluginOptions) {
|
5230
4975
|
return {
|
5231
4976
|
all: async (query, options = {}) => {
|
5232
|
-
const { records, totalCount } = await __privateMethod$1(this,
|
4977
|
+
const { records, totalCount } = await __privateMethod$1(this, _SearchPlugin_instances, search_fn).call(this, query, options, pluginOptions);
|
5233
4978
|
return {
|
5234
4979
|
totalCount,
|
5235
4980
|
records: records.map((record) => {
|
@@ -5239,7 +4984,7 @@ class SearchPlugin extends XataPlugin {
|
|
5239
4984
|
};
|
5240
4985
|
},
|
5241
4986
|
byTable: async (query, options = {}) => {
|
5242
|
-
const { records: rawRecords, totalCount } = await __privateMethod$1(this,
|
4987
|
+
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _SearchPlugin_instances, search_fn).call(this, query, options, pluginOptions);
|
5243
4988
|
const records = rawRecords.reduce((acc, record) => {
|
5244
4989
|
const table = record.xata_table;
|
5245
4990
|
const items = acc[table] ?? [];
|
@@ -5251,7 +4996,7 @@ class SearchPlugin extends XataPlugin {
|
|
5251
4996
|
};
|
5252
4997
|
}
|
5253
4998
|
}
|
5254
|
-
|
4999
|
+
_SearchPlugin_instances = new WeakSet();
|
5255
5000
|
search_fn = async function(query, options, pluginOptions) {
|
5256
5001
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
5257
5002
|
const { records, totalCount } = await searchBranch({
|
@@ -5287,8 +5032,7 @@ function arrayString(val) {
|
|
5287
5032
|
return result;
|
5288
5033
|
}
|
5289
5034
|
function prepareValue(value) {
|
5290
|
-
if (!isDefined(value))
|
5291
|
-
return null;
|
5035
|
+
if (!isDefined(value)) return null;
|
5292
5036
|
if (value instanceof Date) {
|
5293
5037
|
return value.toISOString();
|
5294
5038
|
}
|
@@ -5367,8 +5111,7 @@ function buildDomain(host, region) {
|
|
5367
5111
|
function buildConnectionString({ apiKey, workspacesApiUrl, branch }) {
|
5368
5112
|
const url = isString(workspacesApiUrl) ? workspacesApiUrl : workspacesApiUrl("", {});
|
5369
5113
|
const parts = parseWorkspacesUrlParts(url);
|
5370
|
-
if (!parts)
|
5371
|
-
throw new Error("Invalid workspaces URL");
|
5114
|
+
if (!parts) throw new Error("Invalid workspaces URL");
|
5372
5115
|
const { workspace: workspaceSlug, region, database, host } = parts;
|
5373
5116
|
const domain = buildDomain(host, region);
|
5374
5117
|
const workspace = workspaceSlug.split("-").pop();
|
@@ -5393,39 +5136,24 @@ class TransactionPlugin extends XataPlugin {
|
|
5393
5136
|
}
|
5394
5137
|
}
|
5395
5138
|
|
5396
|
-
var
|
5397
|
-
|
5398
|
-
throw TypeError("Cannot " + msg);
|
5399
|
-
};
|
5400
|
-
var __privateGet = (obj, member, getter) => {
|
5401
|
-
__accessCheck(obj, member, "read from private field");
|
5402
|
-
return getter ? getter.call(obj) : member.get(obj);
|
5403
|
-
};
|
5404
|
-
var __privateAdd = (obj, member, value) => {
|
5405
|
-
if (member.has(obj))
|
5406
|
-
throw TypeError("Cannot add the same private member more than once");
|
5407
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
5408
|
-
};
|
5409
|
-
var __privateSet = (obj, member, value, setter) => {
|
5410
|
-
__accessCheck(obj, member, "write to private field");
|
5411
|
-
member.set(obj, value);
|
5412
|
-
return value;
|
5413
|
-
};
|
5414
|
-
var __privateMethod = (obj, member, method) => {
|
5415
|
-
__accessCheck(obj, member, "access private method");
|
5416
|
-
return method;
|
5139
|
+
var __typeError = (msg) => {
|
5140
|
+
throw TypeError(msg);
|
5417
5141
|
};
|
5142
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
5143
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
5144
|
+
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);
|
5145
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
5146
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
5418
5147
|
const buildClient = (plugins) => {
|
5419
|
-
var _options,
|
5148
|
+
var _options, _instances, parseOptions_fn, getFetchProps_fn, _a;
|
5420
5149
|
return _a = class {
|
5421
5150
|
constructor(options = {}, tables) {
|
5422
|
-
__privateAdd(this,
|
5423
|
-
__privateAdd(this,
|
5424
|
-
|
5425
|
-
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
5151
|
+
__privateAdd(this, _instances);
|
5152
|
+
__privateAdd(this, _options);
|
5153
|
+
const safeOptions = __privateMethod(this, _instances, parseOptions_fn).call(this, options);
|
5426
5154
|
__privateSet(this, _options, safeOptions);
|
5427
5155
|
const pluginOptions = {
|
5428
|
-
...__privateMethod(this,
|
5156
|
+
...__privateMethod(this, _instances, getFetchProps_fn).call(this, safeOptions),
|
5429
5157
|
host: safeOptions.host,
|
5430
5158
|
tables,
|
5431
5159
|
branch: safeOptions.branch
|
@@ -5442,8 +5170,7 @@ const buildClient = (plugins) => {
|
|
5442
5170
|
this.sql = sql;
|
5443
5171
|
this.files = files;
|
5444
5172
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
5445
|
-
if (namespace === void 0)
|
5446
|
-
continue;
|
5173
|
+
if (namespace === void 0) continue;
|
5447
5174
|
this[key] = namespace.build(pluginOptions);
|
5448
5175
|
}
|
5449
5176
|
}
|
@@ -5452,8 +5179,8 @@ const buildClient = (plugins) => {
|
|
5452
5179
|
const branch = __privateGet(this, _options).branch;
|
5453
5180
|
return { databaseURL, branch };
|
5454
5181
|
}
|
5455
|
-
}, _options = new WeakMap(),
|
5456
|
-
const enableBrowser = options?.enableBrowser ??
|
5182
|
+
}, _options = new WeakMap(), _instances = new WeakSet(), parseOptions_fn = function(options) {
|
5183
|
+
const enableBrowser = options?.enableBrowser ?? false;
|
5457
5184
|
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
5458
5185
|
if (isBrowser && !enableBrowser) {
|
5459
5186
|
throw new Error(
|
@@ -5461,8 +5188,9 @@ const buildClient = (plugins) => {
|
|
5461
5188
|
);
|
5462
5189
|
}
|
5463
5190
|
const fetch = getFetchImplementation(options?.fetch);
|
5464
|
-
const databaseURL = options?.databaseURL
|
5465
|
-
const apiKey = options?.apiKey
|
5191
|
+
const databaseURL = options?.databaseURL;
|
5192
|
+
const apiKey = options?.apiKey;
|
5193
|
+
const branch = options?.branch;
|
5466
5194
|
const trace = options?.trace ?? defaultTrace;
|
5467
5195
|
const clientName = options?.clientName;
|
5468
5196
|
const host = options?.host ?? "production";
|
@@ -5473,25 +5201,8 @@ const buildClient = (plugins) => {
|
|
5473
5201
|
if (!databaseURL) {
|
5474
5202
|
throw new Error("Option databaseURL is required");
|
5475
5203
|
}
|
5476
|
-
|
5477
|
-
|
5478
|
-
const branch = options?.branch || previewBranch || envBranch || "main";
|
5479
|
-
if (!!previewBranch && branch !== previewBranch) {
|
5480
|
-
console.warn(
|
5481
|
-
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
5482
|
-
);
|
5483
|
-
} else if (!!envBranch && branch !== envBranch) {
|
5484
|
-
console.warn(
|
5485
|
-
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
5486
|
-
);
|
5487
|
-
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
5488
|
-
console.warn(
|
5489
|
-
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
5490
|
-
);
|
5491
|
-
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
5492
|
-
console.warn(
|
5493
|
-
`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.`
|
5494
|
-
);
|
5204
|
+
if (!branch) {
|
5205
|
+
throw new Error("Option branch is required");
|
5495
5206
|
}
|
5496
5207
|
return {
|
5497
5208
|
fetch,
|
@@ -5505,7 +5216,7 @@ const buildClient = (plugins) => {
|
|
5505
5216
|
clientName,
|
5506
5217
|
xataAgentExtra
|
5507
5218
|
};
|
5508
|
-
},
|
5219
|
+
}, getFetchProps_fn = function({
|
5509
5220
|
fetch,
|
5510
5221
|
apiKey,
|
5511
5222
|
databaseURL,
|
@@ -5546,26 +5257,19 @@ class Serializer {
|
|
5546
5257
|
}
|
5547
5258
|
toJSON(data) {
|
5548
5259
|
function visit(obj) {
|
5549
|
-
if (Array.isArray(obj))
|
5550
|
-
return obj.map(visit);
|
5260
|
+
if (Array.isArray(obj)) return obj.map(visit);
|
5551
5261
|
const type = typeof obj;
|
5552
|
-
if (type === "undefined")
|
5553
|
-
|
5554
|
-
if (
|
5555
|
-
return { [META]: "bigint", [VALUE]: obj.toString() };
|
5556
|
-
if (obj === null || type !== "object")
|
5557
|
-
return obj;
|
5262
|
+
if (type === "undefined") return { [META]: "undefined" };
|
5263
|
+
if (type === "bigint") return { [META]: "bigint", [VALUE]: obj.toString() };
|
5264
|
+
if (obj === null || type !== "object") return obj;
|
5558
5265
|
const constructor = obj.constructor;
|
5559
5266
|
const o = { [META]: constructor.name };
|
5560
5267
|
for (const [key, value] of Object.entries(obj)) {
|
5561
5268
|
o[key] = visit(value);
|
5562
5269
|
}
|
5563
|
-
if (constructor === Date)
|
5564
|
-
|
5565
|
-
if (constructor ===
|
5566
|
-
o[VALUE] = Object.fromEntries(obj);
|
5567
|
-
if (constructor === Set)
|
5568
|
-
o[VALUE] = [...obj];
|
5270
|
+
if (constructor === Date) o[VALUE] = obj.toISOString();
|
5271
|
+
if (constructor === Map) o[VALUE] = Object.fromEntries(obj);
|
5272
|
+
if (constructor === Set) o[VALUE] = [...obj];
|
5569
5273
|
return o;
|
5570
5274
|
}
|
5571
5275
|
return JSON.stringify(visit(data));
|
@@ -5578,16 +5282,11 @@ class Serializer {
|
|
5578
5282
|
if (constructor) {
|
5579
5283
|
return Object.assign(Object.create(constructor.prototype), rest);
|
5580
5284
|
}
|
5581
|
-
if (clazz === "Date")
|
5582
|
-
|
5583
|
-
if (clazz === "
|
5584
|
-
|
5585
|
-
if (clazz === "
|
5586
|
-
return new Map(Object.entries(val));
|
5587
|
-
if (clazz === "bigint")
|
5588
|
-
return BigInt(val);
|
5589
|
-
if (clazz === "undefined")
|
5590
|
-
return void 0;
|
5285
|
+
if (clazz === "Date") return new Date(val);
|
5286
|
+
if (clazz === "Set") return new Set(val);
|
5287
|
+
if (clazz === "Map") return new Map(Object.entries(val));
|
5288
|
+
if (clazz === "bigint") return BigInt(val);
|
5289
|
+
if (clazz === "undefined") return void 0;
|
5591
5290
|
return rest;
|
5592
5291
|
}
|
5593
5292
|
return value;
|
@@ -5602,6 +5301,47 @@ const deserialize = (json) => {
|
|
5602
5301
|
return defaultSerializer.fromJSON(json);
|
5603
5302
|
};
|
5604
5303
|
|
5304
|
+
function parseEnvironment(environment) {
|
5305
|
+
try {
|
5306
|
+
if (typeof environment === "function") {
|
5307
|
+
return new Proxy(
|
5308
|
+
{},
|
5309
|
+
{
|
5310
|
+
get(target) {
|
5311
|
+
return environment(target);
|
5312
|
+
}
|
5313
|
+
}
|
5314
|
+
);
|
5315
|
+
}
|
5316
|
+
if (isObject(environment)) {
|
5317
|
+
return environment;
|
5318
|
+
}
|
5319
|
+
} catch (error) {
|
5320
|
+
}
|
5321
|
+
return {};
|
5322
|
+
}
|
5323
|
+
function buildPreviewBranchName({ org, branch }) {
|
5324
|
+
return `preview-${org}-${branch}`;
|
5325
|
+
}
|
5326
|
+
function getDeployPreviewBranch(environment) {
|
5327
|
+
try {
|
5328
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = parseEnvironment(environment);
|
5329
|
+
if (deployPreviewBranch) return deployPreviewBranch;
|
5330
|
+
switch (deployPreview) {
|
5331
|
+
case "vercel": {
|
5332
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
5333
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
5334
|
+
return void 0;
|
5335
|
+
}
|
5336
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
5337
|
+
}
|
5338
|
+
}
|
5339
|
+
return void 0;
|
5340
|
+
} catch (err) {
|
5341
|
+
return void 0;
|
5342
|
+
}
|
5343
|
+
}
|
5344
|
+
|
5605
5345
|
class XataError extends Error {
|
5606
5346
|
constructor(message, status) {
|
5607
5347
|
super(message);
|
@@ -5654,6 +5394,7 @@ exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
|
5654
5394
|
exports.compareBranchSchemas = compareBranchSchemas;
|
5655
5395
|
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
5656
5396
|
exports.compareMigrationRequest = compareMigrationRequest;
|
5397
|
+
exports.completeMigration = completeMigration;
|
5657
5398
|
exports.contains = contains;
|
5658
5399
|
exports.copyBranch = copyBranch;
|
5659
5400
|
exports.createBranch = createBranch;
|
@@ -5685,9 +5426,7 @@ exports.exists = exists;
|
|
5685
5426
|
exports.fileAccess = fileAccess;
|
5686
5427
|
exports.fileUpload = fileUpload;
|
5687
5428
|
exports.ge = ge;
|
5688
|
-
exports.getAPIKey = getAPIKey;
|
5689
5429
|
exports.getAuthorizationCode = getAuthorizationCode;
|
5690
|
-
exports.getBranch = getBranch;
|
5691
5430
|
exports.getBranchDetails = getBranchDetails;
|
5692
5431
|
exports.getBranchList = getBranchList;
|
5693
5432
|
exports.getBranchMetadata = getBranchMetadata;
|
@@ -5702,7 +5441,7 @@ exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
|
5702
5441
|
exports.getDatabaseList = getDatabaseList;
|
5703
5442
|
exports.getDatabaseMetadata = getDatabaseMetadata;
|
5704
5443
|
exports.getDatabaseSettings = getDatabaseSettings;
|
5705
|
-
exports.
|
5444
|
+
exports.getDeployPreviewBranch = getDeployPreviewBranch;
|
5706
5445
|
exports.getFile = getFile;
|
5707
5446
|
exports.getFileItem = getFileItem;
|
5708
5447
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
@@ -5711,7 +5450,6 @@ exports.getMigrationHistory = getMigrationHistory;
|
|
5711
5450
|
exports.getMigrationJobStatus = getMigrationJobStatus;
|
5712
5451
|
exports.getMigrationRequest = getMigrationRequest;
|
5713
5452
|
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
5714
|
-
exports.getPreviewBranch = getPreviewBranch;
|
5715
5453
|
exports.getRecord = getRecord;
|
5716
5454
|
exports.getSchema = getSchema;
|
5717
5455
|
exports.getTableColumns = getTableColumns;
|
@@ -5773,11 +5511,14 @@ exports.removeWorkspaceMember = removeWorkspaceMember;
|
|
5773
5511
|
exports.renameDatabase = renameDatabase;
|
5774
5512
|
exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
5775
5513
|
exports.resolveBranch = resolveBranch;
|
5514
|
+
exports.rollbackMigration = rollbackMigration;
|
5776
5515
|
exports.searchBranch = searchBranch;
|
5777
5516
|
exports.searchTable = searchTable;
|
5778
5517
|
exports.serialize = serialize;
|
5779
5518
|
exports.setTableSchema = setTableSchema;
|
5519
|
+
exports.sqlBatchQuery = sqlBatchQuery;
|
5780
5520
|
exports.sqlQuery = sqlQuery;
|
5521
|
+
exports.startMigration = startMigration;
|
5781
5522
|
exports.startsWith = startsWith;
|
5782
5523
|
exports.summarizeTable = summarizeTable;
|
5783
5524
|
exports.transformImage = transformImage;
|