@xata.io/client 0.0.0-alpha.vf98a27d → 0.0.0-alpha.vf9999ff4b05d999462008ed970e92ff105361132
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-add-version.log +1 -1
- package/.turbo/turbo-build.log +4 -9
- package/CHANGELOG.md +139 -1
- package/dist/index.cjs +526 -345
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3235 -2595
- package/dist/index.mjs +503 -344
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -20,7 +20,8 @@ const TraceAttributes = {
|
|
20
20
|
HTTP_METHOD: "http.method",
|
21
21
|
HTTP_URL: "http.url",
|
22
22
|
HTTP_ROUTE: "http.route",
|
23
|
-
HTTP_TARGET: "http.target"
|
23
|
+
HTTP_TARGET: "http.target",
|
24
|
+
CLOUDFLARE_RAY_ID: "cf.ray"
|
24
25
|
};
|
25
26
|
|
26
27
|
function notEmpty(value) {
|
@@ -32,8 +33,15 @@ function compact(arr) {
|
|
32
33
|
function compactObject(obj) {
|
33
34
|
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
34
35
|
}
|
36
|
+
function isBlob(value) {
|
37
|
+
try {
|
38
|
+
return value instanceof Blob;
|
39
|
+
} catch (error) {
|
40
|
+
return false;
|
41
|
+
}
|
42
|
+
}
|
35
43
|
function isObject(value) {
|
36
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
|
44
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
37
45
|
}
|
38
46
|
function isDefined(value) {
|
39
47
|
return value !== null && value !== void 0;
|
@@ -208,7 +216,7 @@ function getAPIKey() {
|
|
208
216
|
function getBranch() {
|
209
217
|
try {
|
210
218
|
const { branch } = getEnvironment();
|
211
|
-
return branch
|
219
|
+
return branch;
|
212
220
|
} catch (err) {
|
213
221
|
return void 0;
|
214
222
|
}
|
@@ -236,12 +244,6 @@ function getPreviewBranch() {
|
|
236
244
|
}
|
237
245
|
}
|
238
246
|
|
239
|
-
var __defProp$8 = Object.defineProperty;
|
240
|
-
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
241
|
-
var __publicField$8 = (obj, key, value) => {
|
242
|
-
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
243
|
-
return value;
|
244
|
-
};
|
245
247
|
var __accessCheck$8 = (obj, member, msg) => {
|
246
248
|
if (!member.has(obj))
|
247
249
|
throw TypeError("Cannot " + msg);
|
@@ -265,14 +267,13 @@ var __privateMethod$4 = (obj, member, method) => {
|
|
265
267
|
return method;
|
266
268
|
};
|
267
269
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
268
|
-
const REQUEST_TIMEOUT =
|
270
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
269
271
|
function getFetchImplementation(userFetch) {
|
270
272
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
271
|
-
const
|
273
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
274
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
272
275
|
if (!fetchImpl) {
|
273
|
-
throw new Error(
|
274
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
275
|
-
);
|
276
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
276
277
|
}
|
277
278
|
return fetchImpl;
|
278
279
|
}
|
@@ -282,8 +283,6 @@ class ApiRequestPool {
|
|
282
283
|
__privateAdd$8(this, _fetch, void 0);
|
283
284
|
__privateAdd$8(this, _queue, void 0);
|
284
285
|
__privateAdd$8(this, _concurrency, void 0);
|
285
|
-
__publicField$8(this, "running");
|
286
|
-
__publicField$8(this, "started");
|
287
286
|
__privateSet$8(this, _queue, []);
|
288
287
|
__privateSet$8(this, _concurrency, concurrency);
|
289
288
|
this.running = 0;
|
@@ -303,13 +302,7 @@ class ApiRequestPool {
|
|
303
302
|
const fetchImpl = this.getFetch();
|
304
303
|
const runRequest = async (stalled = false) => {
|
305
304
|
const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
|
306
|
-
const response = await Promise.race([
|
307
|
-
fetchImpl(url, options).then((result) => {
|
308
|
-
cancel();
|
309
|
-
return result;
|
310
|
-
}),
|
311
|
-
promise.then(() => null)
|
312
|
-
]);
|
305
|
+
const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
|
313
306
|
if (!response) {
|
314
307
|
throw new Error("Request timed out");
|
315
308
|
}
|
@@ -320,7 +313,7 @@ class ApiRequestPool {
|
|
320
313
|
}
|
321
314
|
if (stalled) {
|
322
315
|
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
323
|
-
console.warn(`A request to Xata hit
|
316
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
324
317
|
}
|
325
318
|
return response;
|
326
319
|
};
|
@@ -535,26 +528,16 @@ function defaultOnOpen(response) {
|
|
535
528
|
}
|
536
529
|
}
|
537
530
|
|
538
|
-
const VERSION = "0.
|
531
|
+
const VERSION = "0.28.4";
|
539
532
|
|
540
|
-
var __defProp$7 = Object.defineProperty;
|
541
|
-
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
542
|
-
var __publicField$7 = (obj, key, value) => {
|
543
|
-
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
544
|
-
return value;
|
545
|
-
};
|
546
533
|
class ErrorWithCause extends Error {
|
547
534
|
constructor(message, options) {
|
548
535
|
super(message, options);
|
549
|
-
__publicField$7(this, "cause");
|
550
536
|
}
|
551
537
|
}
|
552
538
|
class FetcherError extends ErrorWithCause {
|
553
539
|
constructor(status, data, requestId) {
|
554
540
|
super(getMessage(data));
|
555
|
-
__publicField$7(this, "status");
|
556
|
-
__publicField$7(this, "requestId");
|
557
|
-
__publicField$7(this, "errors");
|
558
541
|
this.status = status;
|
559
542
|
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
560
543
|
this.requestId = requestId;
|
@@ -588,6 +571,67 @@ function getMessage(data) {
|
|
588
571
|
}
|
589
572
|
}
|
590
573
|
|
574
|
+
function getHostUrl(provider, type) {
|
575
|
+
if (isHostProviderAlias(provider)) {
|
576
|
+
return providers[provider][type];
|
577
|
+
} else if (isHostProviderBuilder(provider)) {
|
578
|
+
return provider[type];
|
579
|
+
}
|
580
|
+
throw new Error("Invalid API provider");
|
581
|
+
}
|
582
|
+
const providers = {
|
583
|
+
production: {
|
584
|
+
main: "https://api.xata.io",
|
585
|
+
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
586
|
+
},
|
587
|
+
staging: {
|
588
|
+
main: "https://api.staging-xata.dev",
|
589
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
590
|
+
},
|
591
|
+
dev: {
|
592
|
+
main: "https://api.dev-xata.dev",
|
593
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
594
|
+
},
|
595
|
+
local: {
|
596
|
+
main: "http://localhost:6001",
|
597
|
+
workspaces: "http://{workspaceId}.{region}.localhost:6001"
|
598
|
+
}
|
599
|
+
};
|
600
|
+
function isHostProviderAlias(alias) {
|
601
|
+
return isString(alias) && Object.keys(providers).includes(alias);
|
602
|
+
}
|
603
|
+
function isHostProviderBuilder(builder) {
|
604
|
+
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
605
|
+
}
|
606
|
+
function parseProviderString(provider = "production") {
|
607
|
+
if (isHostProviderAlias(provider)) {
|
608
|
+
return provider;
|
609
|
+
}
|
610
|
+
const [main, workspaces] = provider.split(",");
|
611
|
+
if (!main || !workspaces)
|
612
|
+
return null;
|
613
|
+
return { main, workspaces };
|
614
|
+
}
|
615
|
+
function buildProviderString(provider) {
|
616
|
+
if (isHostProviderAlias(provider))
|
617
|
+
return provider;
|
618
|
+
return `${provider.main},${provider.workspaces}`;
|
619
|
+
}
|
620
|
+
function parseWorkspacesUrlParts(url) {
|
621
|
+
if (!isString(url))
|
622
|
+
return null;
|
623
|
+
const matches = {
|
624
|
+
production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/),
|
625
|
+
staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
|
626
|
+
dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/),
|
627
|
+
local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(\d+)/)
|
628
|
+
};
|
629
|
+
const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
|
630
|
+
if (!isHostProviderAlias(host) || !match)
|
631
|
+
return null;
|
632
|
+
return { workspace: match[1], region: match[2], host };
|
633
|
+
}
|
634
|
+
|
591
635
|
const pool = new ApiRequestPool();
|
592
636
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
593
637
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
@@ -603,6 +647,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
603
647
|
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
604
648
|
};
|
605
649
|
function buildBaseUrl({
|
650
|
+
method,
|
606
651
|
endpoint,
|
607
652
|
path,
|
608
653
|
workspacesApiUrl,
|
@@ -610,7 +655,24 @@ function buildBaseUrl({
|
|
610
655
|
pathParams = {}
|
611
656
|
}) {
|
612
657
|
if (endpoint === "dataPlane") {
|
613
|
-
|
658
|
+
let url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
659
|
+
if (method.toUpperCase() === "PUT" && [
|
660
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
661
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}"
|
662
|
+
].includes(path)) {
|
663
|
+
const { host } = parseWorkspacesUrlParts(url) ?? {};
|
664
|
+
switch (host) {
|
665
|
+
case "production":
|
666
|
+
url = url.replace("xata.sh", "upload.xata.sh");
|
667
|
+
break;
|
668
|
+
case "staging":
|
669
|
+
url = url.replace("staging-xata.dev", "upload.staging-xata.dev");
|
670
|
+
break;
|
671
|
+
case "dev":
|
672
|
+
url = url.replace("dev-xata.dev", "upload.dev-xata.dev");
|
673
|
+
break;
|
674
|
+
}
|
675
|
+
}
|
614
676
|
const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
|
615
677
|
return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
|
616
678
|
}
|
@@ -621,11 +683,14 @@ function hostHeader(url) {
|
|
621
683
|
const { groups } = pattern.exec(url) ?? {};
|
622
684
|
return groups?.host ? { Host: groups.host } : {};
|
623
685
|
}
|
624
|
-
function parseBody(body, headers) {
|
686
|
+
async function parseBody(body, headers) {
|
625
687
|
if (!isDefined(body))
|
626
688
|
return void 0;
|
689
|
+
if (isBlob(body) || typeof body.text === "function") {
|
690
|
+
return body;
|
691
|
+
}
|
627
692
|
const { "Content-Type": contentType } = headers ?? {};
|
628
|
-
if (String(contentType).toLowerCase() === "application/json") {
|
693
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
629
694
|
return JSON.stringify(body);
|
630
695
|
}
|
631
696
|
return body;
|
@@ -656,9 +721,9 @@ async function fetch$1({
|
|
656
721
|
return await trace(
|
657
722
|
`${method.toUpperCase()} ${path}`,
|
658
723
|
async ({ setAttributes }) => {
|
659
|
-
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
724
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
660
725
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
661
|
-
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
726
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\.[^.]+\./, "http://") : fullUrl;
|
662
727
|
setAttributes({
|
663
728
|
[TraceAttributes.HTTP_URL]: url,
|
664
729
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
@@ -682,7 +747,7 @@ async function fetch$1({
|
|
682
747
|
const response = await pool.request(url, {
|
683
748
|
...fetchOptions,
|
684
749
|
method: method.toUpperCase(),
|
685
|
-
body: parseBody(body, headers),
|
750
|
+
body: await parseBody(body, headers),
|
686
751
|
headers,
|
687
752
|
signal
|
688
753
|
});
|
@@ -693,7 +758,8 @@ async function fetch$1({
|
|
693
758
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
694
759
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
695
760
|
[TraceAttributes.HTTP_HOST]: host,
|
696
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
761
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
762
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
697
763
|
});
|
698
764
|
const message = response.headers?.get("x-xata-message");
|
699
765
|
if (message)
|
@@ -738,7 +804,7 @@ function fetchSSERequest({
|
|
738
804
|
clientName,
|
739
805
|
xataAgentExtra
|
740
806
|
}) {
|
741
|
-
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
807
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
742
808
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
743
809
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
744
810
|
void fetchEventSource(url, {
|
@@ -781,6 +847,20 @@ function parseUrl(url) {
|
|
781
847
|
|
782
848
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
783
849
|
|
850
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/apply", method: "post", ...variables, signal });
|
851
|
+
const pgRollStatus = (variables, signal) => dataPlaneFetch({
|
852
|
+
url: "/db/{dbBranchName}/pgroll/status",
|
853
|
+
method: "get",
|
854
|
+
...variables,
|
855
|
+
signal
|
856
|
+
});
|
857
|
+
const pgRollJobStatus = (variables, signal) => dataPlaneFetch({
|
858
|
+
url: "/db/{dbBranchName}/pgroll/jobs/{jobId}",
|
859
|
+
method: "get",
|
860
|
+
...variables,
|
861
|
+
signal
|
862
|
+
});
|
863
|
+
const pgRollMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/migrations", method: "get", ...variables, signal });
|
784
864
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
785
865
|
url: "/dbs/{dbName}",
|
786
866
|
method: "get",
|
@@ -800,6 +880,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
800
880
|
...variables,
|
801
881
|
signal
|
802
882
|
});
|
883
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
884
|
+
url: "/db/{dbBranchName}/schema",
|
885
|
+
method: "get",
|
886
|
+
...variables,
|
887
|
+
signal
|
888
|
+
});
|
803
889
|
const copyBranch = (variables, signal) => dataPlaneFetch({
|
804
890
|
url: "/db/{dbBranchName}/copy",
|
805
891
|
method: "post",
|
@@ -965,12 +1051,6 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
965
1051
|
...variables,
|
966
1052
|
signal
|
967
1053
|
});
|
968
|
-
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
969
|
-
url: "/db/{dbBranchName}/sql",
|
970
|
-
method: "post",
|
971
|
-
...variables,
|
972
|
-
signal
|
973
|
-
});
|
974
1054
|
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
975
1055
|
const askTable = (variables, signal) => dataPlaneFetch({
|
976
1056
|
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
@@ -987,8 +1067,24 @@ const fileAccess = (variables, signal) => dataPlaneFetch({
|
|
987
1067
|
...variables,
|
988
1068
|
signal
|
989
1069
|
});
|
1070
|
+
const fileUpload = (variables, signal) => dataPlaneFetch({
|
1071
|
+
url: "/file/{fileId}",
|
1072
|
+
method: "put",
|
1073
|
+
...variables,
|
1074
|
+
signal
|
1075
|
+
});
|
1076
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
1077
|
+
url: "/db/{dbBranchName}/sql",
|
1078
|
+
method: "post",
|
1079
|
+
...variables,
|
1080
|
+
signal
|
1081
|
+
});
|
990
1082
|
const operationsByTag$2 = {
|
991
1083
|
branch: {
|
1084
|
+
applyMigration,
|
1085
|
+
pgRollStatus,
|
1086
|
+
pgRollJobStatus,
|
1087
|
+
pgRollMigrationHistory,
|
992
1088
|
getBranchList,
|
993
1089
|
getBranchDetails,
|
994
1090
|
createBranch,
|
@@ -1003,6 +1099,7 @@ const operationsByTag$2 = {
|
|
1003
1099
|
resolveBranch
|
1004
1100
|
},
|
1005
1101
|
migrations: {
|
1102
|
+
getSchema,
|
1006
1103
|
getBranchMigrationHistory,
|
1007
1104
|
getBranchMigrationPlan,
|
1008
1105
|
executeBranchMigrationPlan,
|
@@ -1046,29 +1143,24 @@ const operationsByTag$2 = {
|
|
1046
1143
|
deleteRecord,
|
1047
1144
|
bulkInsertTableRecords
|
1048
1145
|
},
|
1049
|
-
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1146
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
|
1050
1147
|
searchAndFilter: {
|
1051
1148
|
queryTable,
|
1052
1149
|
searchBranch,
|
1053
1150
|
searchTable,
|
1054
|
-
sqlQuery,
|
1055
1151
|
vectorSearchTable,
|
1056
1152
|
askTable,
|
1057
1153
|
askTableSession,
|
1058
1154
|
summarizeTable,
|
1059
1155
|
aggregateTable
|
1060
|
-
}
|
1156
|
+
},
|
1157
|
+
sql: { sqlQuery }
|
1061
1158
|
};
|
1062
1159
|
|
1063
1160
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
1064
1161
|
|
1162
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
1065
1163
|
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
1066
|
-
const generateAccessToken = (variables, signal) => controlPlaneFetch({
|
1067
|
-
url: "/oauth/token",
|
1068
|
-
method: "post",
|
1069
|
-
...variables,
|
1070
|
-
signal
|
1071
|
-
});
|
1072
1164
|
const getUser = (variables, signal) => controlPlaneFetch({
|
1073
1165
|
url: "/user",
|
1074
1166
|
method: "get",
|
@@ -1105,6 +1197,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
1105
1197
|
...variables,
|
1106
1198
|
signal
|
1107
1199
|
});
|
1200
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
1201
|
+
url: "/user/oauth/clients",
|
1202
|
+
method: "get",
|
1203
|
+
...variables,
|
1204
|
+
signal
|
1205
|
+
});
|
1206
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1207
|
+
url: "/user/oauth/clients/{clientId}",
|
1208
|
+
method: "delete",
|
1209
|
+
...variables,
|
1210
|
+
signal
|
1211
|
+
});
|
1212
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1213
|
+
url: "/user/oauth/tokens",
|
1214
|
+
method: "get",
|
1215
|
+
...variables,
|
1216
|
+
signal
|
1217
|
+
});
|
1218
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
1219
|
+
url: "/user/oauth/tokens/{token}",
|
1220
|
+
method: "delete",
|
1221
|
+
...variables,
|
1222
|
+
signal
|
1223
|
+
});
|
1224
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
1108
1225
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
1109
1226
|
url: "/workspaces",
|
1110
1227
|
method: "get",
|
@@ -1148,6 +1265,15 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
|
|
1148
1265
|
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
1149
1266
|
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
1150
1267
|
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1268
|
+
const listClusters = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "get", ...variables, signal });
|
1269
|
+
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
1270
|
+
const getCluster = (variables, signal) => controlPlaneFetch({
|
1271
|
+
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
1272
|
+
method: "get",
|
1273
|
+
...variables,
|
1274
|
+
signal
|
1275
|
+
});
|
1276
|
+
const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
|
1151
1277
|
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
1152
1278
|
url: "/workspaces/{workspaceId}/dbs",
|
1153
1279
|
method: "get",
|
@@ -1174,7 +1300,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
1174
1300
|
signal
|
1175
1301
|
});
|
1176
1302
|
const operationsByTag$1 = {
|
1177
|
-
|
1303
|
+
oAuth: {
|
1304
|
+
getAuthorizationCode,
|
1305
|
+
grantAuthorizationCode,
|
1306
|
+
getUserOAuthClients,
|
1307
|
+
deleteUserOAuthClient,
|
1308
|
+
getUserOAuthAccessTokens,
|
1309
|
+
deleteOAuthAccessToken,
|
1310
|
+
updateOAuthAccessToken
|
1311
|
+
},
|
1178
1312
|
users: { getUser, updateUser, deleteUser },
|
1179
1313
|
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
1180
1314
|
workspaces: {
|
@@ -1194,6 +1328,7 @@ const operationsByTag$1 = {
|
|
1194
1328
|
acceptWorkspaceMemberInvite,
|
1195
1329
|
resendWorkspaceMemberInvite
|
1196
1330
|
},
|
1331
|
+
xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
|
1197
1332
|
databases: {
|
1198
1333
|
getDatabaseList,
|
1199
1334
|
createDatabase,
|
@@ -1210,61 +1345,6 @@ const operationsByTag$1 = {
|
|
1210
1345
|
|
1211
1346
|
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
1212
1347
|
|
1213
|
-
function getHostUrl(provider, type) {
|
1214
|
-
if (isHostProviderAlias(provider)) {
|
1215
|
-
return providers[provider][type];
|
1216
|
-
} else if (isHostProviderBuilder(provider)) {
|
1217
|
-
return provider[type];
|
1218
|
-
}
|
1219
|
-
throw new Error("Invalid API provider");
|
1220
|
-
}
|
1221
|
-
const providers = {
|
1222
|
-
production: {
|
1223
|
-
main: "https://api.xata.io",
|
1224
|
-
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
1225
|
-
},
|
1226
|
-
staging: {
|
1227
|
-
main: "https://api.staging-xata.dev",
|
1228
|
-
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1229
|
-
},
|
1230
|
-
dev: {
|
1231
|
-
main: "https://api.dev-xata.dev",
|
1232
|
-
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
1233
|
-
}
|
1234
|
-
};
|
1235
|
-
function isHostProviderAlias(alias) {
|
1236
|
-
return isString(alias) && Object.keys(providers).includes(alias);
|
1237
|
-
}
|
1238
|
-
function isHostProviderBuilder(builder) {
|
1239
|
-
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
1240
|
-
}
|
1241
|
-
function parseProviderString(provider = "production") {
|
1242
|
-
if (isHostProviderAlias(provider)) {
|
1243
|
-
return provider;
|
1244
|
-
}
|
1245
|
-
const [main, workspaces] = provider.split(",");
|
1246
|
-
if (!main || !workspaces)
|
1247
|
-
return null;
|
1248
|
-
return { main, workspaces };
|
1249
|
-
}
|
1250
|
-
function buildProviderString(provider) {
|
1251
|
-
if (isHostProviderAlias(provider))
|
1252
|
-
return provider;
|
1253
|
-
return `${provider.main},${provider.workspaces}`;
|
1254
|
-
}
|
1255
|
-
function parseWorkspacesUrlParts(url) {
|
1256
|
-
if (!isString(url))
|
1257
|
-
return null;
|
1258
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1259
|
-
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1260
|
-
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1261
|
-
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1262
|
-
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
1263
|
-
if (!match)
|
1264
|
-
return null;
|
1265
|
-
return { workspace: match[1], region: match[2] };
|
1266
|
-
}
|
1267
|
-
|
1268
1348
|
var __accessCheck$7 = (obj, member, msg) => {
|
1269
1349
|
if (!member.has(obj))
|
1270
1350
|
throw TypeError("Cannot " + msg);
|
@@ -2589,60 +2669,6 @@ class XataApiPlugin {
|
|
2589
2669
|
class XataPlugin {
|
2590
2670
|
}
|
2591
2671
|
|
2592
|
-
class FilesPlugin extends XataPlugin {
|
2593
|
-
build(pluginOptions) {
|
2594
|
-
return {
|
2595
|
-
download: async (location) => {
|
2596
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2597
|
-
return await getFileItem({
|
2598
|
-
pathParams: {
|
2599
|
-
workspace: "{workspaceId}",
|
2600
|
-
dbBranchName: "{dbBranch}",
|
2601
|
-
region: "{region}",
|
2602
|
-
tableName: table ?? "",
|
2603
|
-
recordId: record ?? "",
|
2604
|
-
columnName: column ?? "",
|
2605
|
-
fileId
|
2606
|
-
},
|
2607
|
-
...pluginOptions,
|
2608
|
-
rawResponse: true
|
2609
|
-
});
|
2610
|
-
},
|
2611
|
-
upload: async (location, file) => {
|
2612
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2613
|
-
return await putFileItem({
|
2614
|
-
pathParams: {
|
2615
|
-
workspace: "{workspaceId}",
|
2616
|
-
dbBranchName: "{dbBranch}",
|
2617
|
-
region: "{region}",
|
2618
|
-
tableName: table ?? "",
|
2619
|
-
recordId: record ?? "",
|
2620
|
-
columnName: column ?? "",
|
2621
|
-
fileId
|
2622
|
-
},
|
2623
|
-
body: file,
|
2624
|
-
...pluginOptions
|
2625
|
-
});
|
2626
|
-
},
|
2627
|
-
delete: async (location) => {
|
2628
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2629
|
-
return await deleteFileItem({
|
2630
|
-
pathParams: {
|
2631
|
-
workspace: "{workspaceId}",
|
2632
|
-
dbBranchName: "{dbBranch}",
|
2633
|
-
region: "{region}",
|
2634
|
-
tableName: table ?? "",
|
2635
|
-
recordId: record ?? "",
|
2636
|
-
columnName: column ?? "",
|
2637
|
-
fileId
|
2638
|
-
},
|
2639
|
-
...pluginOptions
|
2640
|
-
});
|
2641
|
-
}
|
2642
|
-
};
|
2643
|
-
}
|
2644
|
-
}
|
2645
|
-
|
2646
2672
|
function buildTransformString(transformations) {
|
2647
2673
|
return transformations.flatMap(
|
2648
2674
|
(t) => Object.entries(t).map(([key, value]) => {
|
@@ -2658,71 +2684,33 @@ function buildTransformString(transformations) {
|
|
2658
2684
|
})
|
2659
2685
|
).join(",");
|
2660
2686
|
}
|
2661
|
-
function transformImage(url, transformations) {
|
2687
|
+
function transformImage(url, ...transformations) {
|
2662
2688
|
if (!isDefined(url))
|
2663
2689
|
return void 0;
|
2664
|
-
const
|
2690
|
+
const newTransformations = buildTransformString(transformations);
|
2665
2691
|
const { hostname, pathname, search } = new URL(url);
|
2666
|
-
|
2692
|
+
const pathParts = pathname.split("/");
|
2693
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
2694
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
2695
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
2696
|
+
const path = pathParts.join("/");
|
2697
|
+
return `https://${hostname}${transform}${path}${search}`;
|
2667
2698
|
}
|
2668
2699
|
|
2669
|
-
var __defProp$6 = Object.defineProperty;
|
2670
|
-
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2671
|
-
var __publicField$6 = (obj, key, value) => {
|
2672
|
-
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2673
|
-
return value;
|
2674
|
-
};
|
2675
2700
|
class XataFile {
|
2676
2701
|
constructor(file) {
|
2677
|
-
|
2678
|
-
* Name of this file.
|
2679
|
-
*/
|
2680
|
-
__publicField$6(this, "name");
|
2681
|
-
/**
|
2682
|
-
* Media type of this file.
|
2683
|
-
*/
|
2684
|
-
__publicField$6(this, "mediaType");
|
2685
|
-
/**
|
2686
|
-
* Base64 encoded content of this file.
|
2687
|
-
*/
|
2688
|
-
__publicField$6(this, "base64Content");
|
2689
|
-
/**
|
2690
|
-
* Whether to enable public url for this file.
|
2691
|
-
*/
|
2692
|
-
__publicField$6(this, "enablePublicUrl");
|
2693
|
-
/**
|
2694
|
-
* Timeout for the signed url.
|
2695
|
-
*/
|
2696
|
-
__publicField$6(this, "signedUrlTimeout");
|
2697
|
-
/**
|
2698
|
-
* Size of this file.
|
2699
|
-
*/
|
2700
|
-
__publicField$6(this, "size");
|
2701
|
-
/**
|
2702
|
-
* Version of this file.
|
2703
|
-
*/
|
2704
|
-
__publicField$6(this, "version");
|
2705
|
-
/**
|
2706
|
-
* Url of this file.
|
2707
|
-
*/
|
2708
|
-
__publicField$6(this, "url");
|
2709
|
-
/**
|
2710
|
-
* Signed url of this file.
|
2711
|
-
*/
|
2712
|
-
__publicField$6(this, "signedUrl");
|
2713
|
-
/**
|
2714
|
-
* Attributes of this file.
|
2715
|
-
*/
|
2716
|
-
__publicField$6(this, "attributes");
|
2702
|
+
this.id = file.id;
|
2717
2703
|
this.name = file.name;
|
2718
|
-
this.mediaType = file.mediaType
|
2704
|
+
this.mediaType = file.mediaType;
|
2719
2705
|
this.base64Content = file.base64Content;
|
2720
2706
|
this.enablePublicUrl = file.enablePublicUrl;
|
2721
2707
|
this.signedUrlTimeout = file.signedUrlTimeout;
|
2708
|
+
this.uploadUrlTimeout = file.uploadUrlTimeout;
|
2722
2709
|
this.size = file.size;
|
2723
2710
|
this.version = file.version;
|
2724
2711
|
this.url = file.url;
|
2725
2712
|
this.signedUrl = file.signedUrl;
|
2713
|
+
this.uploadUrl = file.uploadUrl;
|
2726
2714
|
this.attributes = file.attributes;
|
2727
2715
|
}
|
2728
2716
|
static fromBuffer(buffer, options = {}) {
|
@@ -2775,8 +2763,12 @@ class XataFile {
|
|
2775
2763
|
if (!this.base64Content) {
|
2776
2764
|
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2777
2765
|
}
|
2778
|
-
const
|
2779
|
-
|
2766
|
+
const binary = atob(this.base64Content);
|
2767
|
+
const uint8Array = new Uint8Array(binary.length);
|
2768
|
+
for (let i = 0; i < binary.length; i++) {
|
2769
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2770
|
+
}
|
2771
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
2780
2772
|
}
|
2781
2773
|
static fromString(string, options = {}) {
|
2782
2774
|
const base64Content = btoa(string);
|
@@ -2799,16 +2791,27 @@ class XataFile {
|
|
2799
2791
|
}
|
2800
2792
|
transform(...options) {
|
2801
2793
|
return {
|
2802
|
-
url: transformImage(this.url, options),
|
2803
|
-
signedUrl: transformImage(this.signedUrl, options)
|
2794
|
+
url: transformImage(this.url, ...options),
|
2795
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
2796
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
2797
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
2804
2798
|
};
|
2805
2799
|
}
|
2806
2800
|
}
|
2807
2801
|
const parseInputFileEntry = async (entry) => {
|
2808
2802
|
if (!isDefined(entry))
|
2809
2803
|
return null;
|
2810
|
-
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2811
|
-
return compactObject({
|
2804
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
|
2805
|
+
return compactObject({
|
2806
|
+
id,
|
2807
|
+
// Name cannot be an empty string in our API
|
2808
|
+
name: name ? name : void 0,
|
2809
|
+
mediaType,
|
2810
|
+
base64Content,
|
2811
|
+
enablePublicUrl,
|
2812
|
+
signedUrlTimeout,
|
2813
|
+
uploadUrlTimeout
|
2814
|
+
});
|
2812
2815
|
};
|
2813
2816
|
|
2814
2817
|
function cleanFilter(filter) {
|
@@ -2838,12 +2841,25 @@ function cleanFilter(filter) {
|
|
2838
2841
|
return Object.keys(values).length > 0 ? values : void 0;
|
2839
2842
|
}
|
2840
2843
|
|
2841
|
-
|
2842
|
-
|
2843
|
-
|
2844
|
-
|
2845
|
-
|
2846
|
-
|
2844
|
+
function stringifyJson(value) {
|
2845
|
+
if (!isDefined(value))
|
2846
|
+
return value;
|
2847
|
+
if (isString(value))
|
2848
|
+
return value;
|
2849
|
+
try {
|
2850
|
+
return JSON.stringify(value);
|
2851
|
+
} catch (e) {
|
2852
|
+
return value;
|
2853
|
+
}
|
2854
|
+
}
|
2855
|
+
function parseJson(value) {
|
2856
|
+
try {
|
2857
|
+
return JSON.parse(value);
|
2858
|
+
} catch (e) {
|
2859
|
+
return value;
|
2860
|
+
}
|
2861
|
+
}
|
2862
|
+
|
2847
2863
|
var __accessCheck$6 = (obj, member, msg) => {
|
2848
2864
|
if (!member.has(obj))
|
2849
2865
|
throw TypeError("Cannot " + msg);
|
@@ -2866,14 +2882,6 @@ var _query, _page;
|
|
2866
2882
|
class Page {
|
2867
2883
|
constructor(query, meta, records = []) {
|
2868
2884
|
__privateAdd$6(this, _query, void 0);
|
2869
|
-
/**
|
2870
|
-
* Page metadata, required to retrieve additional records.
|
2871
|
-
*/
|
2872
|
-
__publicField$5(this, "meta");
|
2873
|
-
/**
|
2874
|
-
* The set of results for this page.
|
2875
|
-
*/
|
2876
|
-
__publicField$5(this, "records");
|
2877
2885
|
__privateSet$6(this, _query, query);
|
2878
2886
|
this.meta = meta;
|
2879
2887
|
this.records = new RecordArray(this, records);
|
@@ -2923,9 +2931,9 @@ class Page {
|
|
2923
2931
|
}
|
2924
2932
|
}
|
2925
2933
|
_query = new WeakMap();
|
2926
|
-
const PAGINATION_MAX_SIZE =
|
2934
|
+
const PAGINATION_MAX_SIZE = 1e3;
|
2927
2935
|
const PAGINATION_DEFAULT_SIZE = 20;
|
2928
|
-
const PAGINATION_MAX_OFFSET =
|
2936
|
+
const PAGINATION_MAX_OFFSET = 49e3;
|
2929
2937
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
2930
2938
|
function isCursorPaginationOptions(options) {
|
2931
2939
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
@@ -3004,12 +3012,6 @@ const _RecordArray = class _RecordArray extends Array {
|
|
3004
3012
|
_page = new WeakMap();
|
3005
3013
|
let RecordArray = _RecordArray;
|
3006
3014
|
|
3007
|
-
var __defProp$4 = Object.defineProperty;
|
3008
|
-
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
3009
|
-
var __publicField$4 = (obj, key, value) => {
|
3010
|
-
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
3011
|
-
return value;
|
3012
|
-
};
|
3013
3015
|
var __accessCheck$5 = (obj, member, msg) => {
|
3014
3016
|
if (!member.has(obj))
|
3015
3017
|
throw TypeError("Cannot " + msg);
|
@@ -3040,8 +3042,8 @@ const _Query = class _Query {
|
|
3040
3042
|
__privateAdd$5(this, _repository, void 0);
|
3041
3043
|
__privateAdd$5(this, _data, { filter: {} });
|
3042
3044
|
// Implements pagination
|
3043
|
-
|
3044
|
-
|
3045
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
3046
|
+
this.records = new RecordArray(this, []);
|
3045
3047
|
__privateSet$5(this, _table$1, table);
|
3046
3048
|
if (repository) {
|
3047
3049
|
__privateSet$5(this, _repository, repository);
|
@@ -3296,7 +3298,8 @@ const RecordColumnTypes = [
|
|
3296
3298
|
"datetime",
|
3297
3299
|
"vector",
|
3298
3300
|
"file[]",
|
3299
|
-
"file"
|
3301
|
+
"file",
|
3302
|
+
"json"
|
3300
3303
|
];
|
3301
3304
|
function isIdentifiable(x) {
|
3302
3305
|
return isObject(x) && isString(x?.id);
|
@@ -3307,6 +3310,24 @@ function isXataRecord(x) {
|
|
3307
3310
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
3308
3311
|
}
|
3309
3312
|
|
3313
|
+
function isValidExpandedColumn(column) {
|
3314
|
+
return isObject(column) && isString(column.name);
|
3315
|
+
}
|
3316
|
+
function isValidSelectableColumns(columns) {
|
3317
|
+
if (!Array.isArray(columns)) {
|
3318
|
+
return false;
|
3319
|
+
}
|
3320
|
+
return columns.every((column) => {
|
3321
|
+
if (typeof column === "string") {
|
3322
|
+
return true;
|
3323
|
+
}
|
3324
|
+
if (typeof column === "object") {
|
3325
|
+
return isValidExpandedColumn(column);
|
3326
|
+
}
|
3327
|
+
return false;
|
3328
|
+
});
|
3329
|
+
}
|
3330
|
+
|
3310
3331
|
function isSortFilterString(value) {
|
3311
3332
|
return isString(value);
|
3312
3333
|
}
|
@@ -3407,24 +3428,24 @@ class RestRepository extends Query {
|
|
3407
3428
|
if (a.length === 0)
|
3408
3429
|
return [];
|
3409
3430
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
3410
|
-
const columns =
|
3431
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3411
3432
|
const result = await this.read(ids, columns);
|
3412
3433
|
return result;
|
3413
3434
|
}
|
3414
3435
|
if (isString(a) && isObject(b)) {
|
3415
3436
|
if (a === "")
|
3416
3437
|
throw new Error("The id can't be empty");
|
3417
|
-
const columns =
|
3438
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3418
3439
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
3419
3440
|
}
|
3420
3441
|
if (isObject(a) && isString(a.id)) {
|
3421
3442
|
if (a.id === "")
|
3422
3443
|
throw new Error("The id can't be empty");
|
3423
|
-
const columns =
|
3444
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3424
3445
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
3425
3446
|
}
|
3426
3447
|
if (isObject(a)) {
|
3427
|
-
const columns =
|
3448
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3428
3449
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
3429
3450
|
}
|
3430
3451
|
throw new Error("Invalid arguments for create method");
|
@@ -3432,7 +3453,7 @@ class RestRepository extends Query {
|
|
3432
3453
|
}
|
3433
3454
|
async read(a, b) {
|
3434
3455
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
3435
|
-
const columns =
|
3456
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3436
3457
|
if (Array.isArray(a)) {
|
3437
3458
|
if (a.length === 0)
|
3438
3459
|
return [];
|
@@ -3459,7 +3480,13 @@ class RestRepository extends Query {
|
|
3459
3480
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3460
3481
|
});
|
3461
3482
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3462
|
-
return initObject(
|
3483
|
+
return initObject(
|
3484
|
+
__privateGet$4(this, _db),
|
3485
|
+
schemaTables,
|
3486
|
+
__privateGet$4(this, _table),
|
3487
|
+
response,
|
3488
|
+
columns
|
3489
|
+
);
|
3463
3490
|
} catch (e) {
|
3464
3491
|
if (isObject(e) && e.status === 404) {
|
3465
3492
|
return null;
|
@@ -3501,17 +3528,17 @@ class RestRepository extends Query {
|
|
3501
3528
|
ifVersion,
|
3502
3529
|
upsert: false
|
3503
3530
|
});
|
3504
|
-
const columns =
|
3531
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3505
3532
|
const result = await this.read(a, columns);
|
3506
3533
|
return result;
|
3507
3534
|
}
|
3508
3535
|
try {
|
3509
3536
|
if (isString(a) && isObject(b)) {
|
3510
|
-
const columns =
|
3537
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3511
3538
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3512
3539
|
}
|
3513
3540
|
if (isObject(a) && isString(a.id)) {
|
3514
|
-
const columns =
|
3541
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3515
3542
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3516
3543
|
}
|
3517
3544
|
} catch (error) {
|
@@ -3551,20 +3578,20 @@ class RestRepository extends Query {
|
|
3551
3578
|
ifVersion,
|
3552
3579
|
upsert: true
|
3553
3580
|
});
|
3554
|
-
const columns =
|
3581
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3555
3582
|
const result = await this.read(a, columns);
|
3556
3583
|
return result;
|
3557
3584
|
}
|
3558
3585
|
if (isString(a) && isObject(b)) {
|
3559
3586
|
if (a === "")
|
3560
3587
|
throw new Error("The id can't be empty");
|
3561
|
-
const columns =
|
3588
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3562
3589
|
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3563
3590
|
}
|
3564
3591
|
if (isObject(a) && isString(a.id)) {
|
3565
3592
|
if (a.id === "")
|
3566
3593
|
throw new Error("The id can't be empty");
|
3567
|
-
const columns =
|
3594
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3568
3595
|
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3569
3596
|
}
|
3570
3597
|
if (!isDefined(a) && isObject(b)) {
|
@@ -3583,20 +3610,20 @@ class RestRepository extends Query {
|
|
3583
3610
|
if (a.length === 0)
|
3584
3611
|
return [];
|
3585
3612
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
3586
|
-
const columns =
|
3613
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3587
3614
|
const result = await this.read(ids, columns);
|
3588
3615
|
return result;
|
3589
3616
|
}
|
3590
3617
|
if (isString(a) && isObject(b)) {
|
3591
3618
|
if (a === "")
|
3592
3619
|
throw new Error("The id can't be empty");
|
3593
|
-
const columns =
|
3620
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3594
3621
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3595
3622
|
}
|
3596
3623
|
if (isObject(a) && isString(a.id)) {
|
3597
3624
|
if (a.id === "")
|
3598
3625
|
throw new Error("The id can't be empty");
|
3599
|
-
const columns =
|
3626
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3600
3627
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3601
3628
|
}
|
3602
3629
|
if (!isDefined(a) && isObject(b)) {
|
@@ -3620,7 +3647,7 @@ class RestRepository extends Query {
|
|
3620
3647
|
return o.id;
|
3621
3648
|
throw new Error("Invalid arguments for delete method");
|
3622
3649
|
});
|
3623
|
-
const columns =
|
3650
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3624
3651
|
const result = await this.read(a, columns);
|
3625
3652
|
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
3626
3653
|
return result;
|
@@ -3654,7 +3681,7 @@ class RestRepository extends Query {
|
|
3654
3681
|
}
|
3655
3682
|
async search(query, options = {}) {
|
3656
3683
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
3657
|
-
const { records } = await searchTable({
|
3684
|
+
const { records, totalCount } = await searchTable({
|
3658
3685
|
pathParams: {
|
3659
3686
|
workspace: "{workspaceId}",
|
3660
3687
|
dbBranchName: "{dbBranch}",
|
@@ -3674,12 +3701,15 @@ class RestRepository extends Query {
|
|
3674
3701
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3675
3702
|
});
|
3676
3703
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3677
|
-
return
|
3704
|
+
return {
|
3705
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3706
|
+
totalCount
|
3707
|
+
};
|
3678
3708
|
});
|
3679
3709
|
}
|
3680
3710
|
async vectorSearch(column, query, options) {
|
3681
3711
|
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3682
|
-
const { records } = await vectorSearchTable({
|
3712
|
+
const { records, totalCount } = await vectorSearchTable({
|
3683
3713
|
pathParams: {
|
3684
3714
|
workspace: "{workspaceId}",
|
3685
3715
|
dbBranchName: "{dbBranch}",
|
@@ -3696,7 +3726,10 @@ class RestRepository extends Query {
|
|
3696
3726
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3697
3727
|
});
|
3698
3728
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3699
|
-
return
|
3729
|
+
return {
|
3730
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3731
|
+
totalCount
|
3732
|
+
};
|
3700
3733
|
});
|
3701
3734
|
}
|
3702
3735
|
async aggregate(aggs, filter) {
|
@@ -3739,7 +3772,13 @@ class RestRepository extends Query {
|
|
3739
3772
|
});
|
3740
3773
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3741
3774
|
const records = objects.map(
|
3742
|
-
(record) => initObject(
|
3775
|
+
(record) => initObject(
|
3776
|
+
__privateGet$4(this, _db),
|
3777
|
+
schemaTables,
|
3778
|
+
__privateGet$4(this, _table),
|
3779
|
+
record,
|
3780
|
+
data.columns ?? ["*"]
|
3781
|
+
)
|
3743
3782
|
);
|
3744
3783
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
3745
3784
|
return new Page(query, meta, records);
|
@@ -3766,7 +3805,13 @@ class RestRepository extends Query {
|
|
3766
3805
|
},
|
3767
3806
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3768
3807
|
});
|
3769
|
-
|
3808
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3809
|
+
return {
|
3810
|
+
...result,
|
3811
|
+
summaries: result.summaries.map(
|
3812
|
+
(summary) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), summary, data.columns ?? [])
|
3813
|
+
)
|
3814
|
+
};
|
3770
3815
|
});
|
3771
3816
|
}
|
3772
3817
|
ask(question, options) {
|
@@ -4045,19 +4090,15 @@ transformObjectToApi_fn = async function(object) {
|
|
4045
4090
|
case "file[]":
|
4046
4091
|
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4047
4092
|
break;
|
4093
|
+
case "json":
|
4094
|
+
result[key] = stringifyJson(value);
|
4095
|
+
break;
|
4048
4096
|
default:
|
4049
4097
|
result[key] = value;
|
4050
4098
|
}
|
4051
4099
|
}
|
4052
4100
|
return result;
|
4053
4101
|
};
|
4054
|
-
const removeLinksFromObject = (object) => {
|
4055
|
-
return Object.entries(object).reduce((acc, [key, value]) => {
|
4056
|
-
if (key === "xata")
|
4057
|
-
return acc;
|
4058
|
-
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
4059
|
-
}, {});
|
4060
|
-
};
|
4061
4102
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
4062
4103
|
const data = {};
|
4063
4104
|
const { xata, ...rest } = object ?? {};
|
@@ -4088,13 +4129,19 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4088
4129
|
if (item === column.name) {
|
4089
4130
|
return [...acc, "*"];
|
4090
4131
|
}
|
4091
|
-
if (item.startsWith(`${column.name}.`)) {
|
4132
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
4092
4133
|
const [, ...path] = item.split(".");
|
4093
4134
|
return [...acc, path.join(".")];
|
4094
4135
|
}
|
4095
4136
|
return acc;
|
4096
4137
|
}, []);
|
4097
|
-
data[column.name] = initObject(
|
4138
|
+
data[column.name] = initObject(
|
4139
|
+
db,
|
4140
|
+
schemaTables,
|
4141
|
+
linkTable,
|
4142
|
+
value,
|
4143
|
+
selectedLinkColumns
|
4144
|
+
);
|
4098
4145
|
} else {
|
4099
4146
|
data[column.name] = null;
|
4100
4147
|
}
|
@@ -4106,6 +4153,9 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4106
4153
|
case "file[]":
|
4107
4154
|
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4108
4155
|
break;
|
4156
|
+
case "json":
|
4157
|
+
data[column.name] = parseJson(value);
|
4158
|
+
break;
|
4109
4159
|
default:
|
4110
4160
|
data[column.name] = value ?? null;
|
4111
4161
|
if (column.notNull === true && value === null) {
|
@@ -4115,33 +4165,34 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4115
4165
|
}
|
4116
4166
|
}
|
4117
4167
|
const record = { ...data };
|
4118
|
-
const serializable = { xata, ...removeLinksFromObject(data) };
|
4119
4168
|
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
4120
4169
|
record.read = function(columns2) {
|
4121
4170
|
return db[table].read(record["id"], columns2);
|
4122
4171
|
};
|
4123
4172
|
record.update = function(data2, b, c) {
|
4124
|
-
const columns2 =
|
4173
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
4125
4174
|
const ifVersion = parseIfVersion(b, c);
|
4126
4175
|
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
4127
4176
|
};
|
4128
4177
|
record.replace = function(data2, b, c) {
|
4129
|
-
const columns2 =
|
4178
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
4130
4179
|
const ifVersion = parseIfVersion(b, c);
|
4131
4180
|
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
4132
4181
|
};
|
4133
4182
|
record.delete = function() {
|
4134
4183
|
return db[table].delete(record["id"]);
|
4135
4184
|
};
|
4136
|
-
|
4185
|
+
if (metadata !== void 0) {
|
4186
|
+
record.xata = Object.freeze(metadata);
|
4187
|
+
}
|
4137
4188
|
record.getMetadata = function() {
|
4138
4189
|
return record.xata;
|
4139
4190
|
};
|
4140
4191
|
record.toSerializable = function() {
|
4141
|
-
return JSON.parse(JSON.stringify(
|
4192
|
+
return JSON.parse(JSON.stringify(record));
|
4142
4193
|
};
|
4143
4194
|
record.toString = function() {
|
4144
|
-
return JSON.stringify(
|
4195
|
+
return JSON.stringify(record);
|
4145
4196
|
};
|
4146
4197
|
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
4147
4198
|
Object.defineProperty(record, prop, { enumerable: false });
|
@@ -4159,7 +4210,7 @@ function extractId(value) {
|
|
4159
4210
|
function isValidColumn(columns, column) {
|
4160
4211
|
if (columns.includes("*"))
|
4161
4212
|
return true;
|
4162
|
-
return columns.filter((item) => item.startsWith(column.name)).length > 0;
|
4213
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
4163
4214
|
}
|
4164
4215
|
function parseIfVersion(...args) {
|
4165
4216
|
for (const arg of args) {
|
@@ -4170,12 +4221,6 @@ function parseIfVersion(...args) {
|
|
4170
4221
|
return void 0;
|
4171
4222
|
}
|
4172
4223
|
|
4173
|
-
var __defProp$3 = Object.defineProperty;
|
4174
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4175
|
-
var __publicField$3 = (obj, key, value) => {
|
4176
|
-
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4177
|
-
return value;
|
4178
|
-
};
|
4179
4224
|
var __accessCheck$3 = (obj, member, msg) => {
|
4180
4225
|
if (!member.has(obj))
|
4181
4226
|
throw TypeError("Cannot " + msg);
|
@@ -4198,8 +4243,6 @@ var _map;
|
|
4198
4243
|
class SimpleCache {
|
4199
4244
|
constructor(options = {}) {
|
4200
4245
|
__privateAdd$3(this, _map, void 0);
|
4201
|
-
__publicField$3(this, "capacity");
|
4202
|
-
__publicField$3(this, "defaultQueryTTL");
|
4203
4246
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
4204
4247
|
this.capacity = options.max ?? 500;
|
4205
4248
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
@@ -4244,10 +4287,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
4244
4287
|
const startsWith = (value) => ({ $startsWith: value });
|
4245
4288
|
const endsWith = (value) => ({ $endsWith: value });
|
4246
4289
|
const pattern = (value) => ({ $pattern: value });
|
4290
|
+
const iPattern = (value) => ({ $iPattern: value });
|
4247
4291
|
const is = (value) => ({ $is: value });
|
4248
4292
|
const equals = is;
|
4249
4293
|
const isNot = (value) => ({ $isNot: value });
|
4250
4294
|
const contains = (value) => ({ $contains: value });
|
4295
|
+
const iContains = (value) => ({ $iContains: value });
|
4251
4296
|
const includes = (value) => ({ $includes: value });
|
4252
4297
|
const includesAll = (value) => ({ $includesAll: value });
|
4253
4298
|
const includesNone = (value) => ({ $includesNone: value });
|
@@ -4303,6 +4348,80 @@ class SchemaPlugin extends XataPlugin {
|
|
4303
4348
|
_tables = new WeakMap();
|
4304
4349
|
_schemaTables$1 = new WeakMap();
|
4305
4350
|
|
4351
|
+
class FilesPlugin extends XataPlugin {
|
4352
|
+
build(pluginOptions) {
|
4353
|
+
return {
|
4354
|
+
download: async (location) => {
|
4355
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4356
|
+
return await getFileItem({
|
4357
|
+
pathParams: {
|
4358
|
+
workspace: "{workspaceId}",
|
4359
|
+
dbBranchName: "{dbBranch}",
|
4360
|
+
region: "{region}",
|
4361
|
+
tableName: table ?? "",
|
4362
|
+
recordId: record ?? "",
|
4363
|
+
columnName: column ?? "",
|
4364
|
+
fileId
|
4365
|
+
},
|
4366
|
+
...pluginOptions,
|
4367
|
+
rawResponse: true
|
4368
|
+
});
|
4369
|
+
},
|
4370
|
+
upload: async (location, file, options) => {
|
4371
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4372
|
+
const resolvedFile = await file;
|
4373
|
+
const contentType = options?.mediaType || getContentType(resolvedFile);
|
4374
|
+
const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
|
4375
|
+
return await putFileItem({
|
4376
|
+
...pluginOptions,
|
4377
|
+
pathParams: {
|
4378
|
+
workspace: "{workspaceId}",
|
4379
|
+
dbBranchName: "{dbBranch}",
|
4380
|
+
region: "{region}",
|
4381
|
+
tableName: table ?? "",
|
4382
|
+
recordId: record ?? "",
|
4383
|
+
columnName: column ?? "",
|
4384
|
+
fileId
|
4385
|
+
},
|
4386
|
+
body,
|
4387
|
+
headers: { "Content-Type": contentType }
|
4388
|
+
});
|
4389
|
+
},
|
4390
|
+
delete: async (location) => {
|
4391
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4392
|
+
return await deleteFileItem({
|
4393
|
+
pathParams: {
|
4394
|
+
workspace: "{workspaceId}",
|
4395
|
+
dbBranchName: "{dbBranch}",
|
4396
|
+
region: "{region}",
|
4397
|
+
tableName: table ?? "",
|
4398
|
+
recordId: record ?? "",
|
4399
|
+
columnName: column ?? "",
|
4400
|
+
fileId
|
4401
|
+
},
|
4402
|
+
...pluginOptions
|
4403
|
+
});
|
4404
|
+
}
|
4405
|
+
};
|
4406
|
+
}
|
4407
|
+
}
|
4408
|
+
function getContentType(file) {
|
4409
|
+
if (typeof file === "string") {
|
4410
|
+
return "text/plain";
|
4411
|
+
}
|
4412
|
+
if ("mediaType" in file && file.mediaType !== void 0) {
|
4413
|
+
return file.mediaType;
|
4414
|
+
}
|
4415
|
+
if (isBlob(file)) {
|
4416
|
+
return file.type;
|
4417
|
+
}
|
4418
|
+
try {
|
4419
|
+
return file.type;
|
4420
|
+
} catch (e) {
|
4421
|
+
}
|
4422
|
+
return "application/octet-stream";
|
4423
|
+
}
|
4424
|
+
|
4306
4425
|
var __accessCheck$1 = (obj, member, msg) => {
|
4307
4426
|
if (!member.has(obj))
|
4308
4427
|
throw TypeError("Cannot " + msg);
|
@@ -4338,22 +4457,26 @@ class SearchPlugin extends XataPlugin {
|
|
4338
4457
|
build(pluginOptions) {
|
4339
4458
|
return {
|
4340
4459
|
all: async (query, options = {}) => {
|
4341
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4460
|
+
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4342
4461
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4343
|
-
return
|
4344
|
-
|
4345
|
-
|
4346
|
-
|
4462
|
+
return {
|
4463
|
+
totalCount,
|
4464
|
+
records: records.map((record) => {
|
4465
|
+
const { table = "orphan" } = record.xata;
|
4466
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
4467
|
+
})
|
4468
|
+
};
|
4347
4469
|
},
|
4348
4470
|
byTable: async (query, options = {}) => {
|
4349
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4471
|
+
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4350
4472
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4351
|
-
|
4473
|
+
const records = rawRecords.reduce((acc, record) => {
|
4352
4474
|
const { table = "orphan" } = record.xata;
|
4353
4475
|
const items = acc[table] ?? [];
|
4354
4476
|
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
4355
4477
|
return { ...acc, [table]: [...items, item] };
|
4356
4478
|
}, {});
|
4479
|
+
return { totalCount, records };
|
4357
4480
|
}
|
4358
4481
|
};
|
4359
4482
|
}
|
@@ -4362,13 +4485,13 @@ _schemaTables = new WeakMap();
|
|
4362
4485
|
_search = new WeakSet();
|
4363
4486
|
search_fn = async function(query, options, pluginOptions) {
|
4364
4487
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
4365
|
-
const { records } = await searchBranch({
|
4488
|
+
const { records, totalCount } = await searchBranch({
|
4366
4489
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4367
4490
|
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
4368
4491
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
4369
4492
|
...pluginOptions
|
4370
4493
|
});
|
4371
|
-
return records;
|
4494
|
+
return { records, totalCount };
|
4372
4495
|
};
|
4373
4496
|
_getSchemaTables = new WeakSet();
|
4374
4497
|
getSchemaTables_fn = async function(pluginOptions) {
|
@@ -4382,6 +4505,78 @@ getSchemaTables_fn = async function(pluginOptions) {
|
|
4382
4505
|
return schema.tables;
|
4383
4506
|
};
|
4384
4507
|
|
4508
|
+
function escapeElement(elementRepresentation) {
|
4509
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
4510
|
+
return '"' + escaped + '"';
|
4511
|
+
}
|
4512
|
+
function arrayString(val) {
|
4513
|
+
let result = "{";
|
4514
|
+
for (let i = 0; i < val.length; i++) {
|
4515
|
+
if (i > 0) {
|
4516
|
+
result = result + ",";
|
4517
|
+
}
|
4518
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
4519
|
+
result = result + "NULL";
|
4520
|
+
} else if (Array.isArray(val[i])) {
|
4521
|
+
result = result + arrayString(val[i]);
|
4522
|
+
} else if (val[i] instanceof Buffer) {
|
4523
|
+
result += "\\\\x" + val[i].toString("hex");
|
4524
|
+
} else {
|
4525
|
+
result += escapeElement(prepareValue(val[i]));
|
4526
|
+
}
|
4527
|
+
}
|
4528
|
+
result = result + "}";
|
4529
|
+
return result;
|
4530
|
+
}
|
4531
|
+
function prepareValue(value) {
|
4532
|
+
if (!isDefined(value))
|
4533
|
+
return null;
|
4534
|
+
if (value instanceof Date) {
|
4535
|
+
return value.toISOString();
|
4536
|
+
}
|
4537
|
+
if (Array.isArray(value)) {
|
4538
|
+
return arrayString(value);
|
4539
|
+
}
|
4540
|
+
if (isObject(value)) {
|
4541
|
+
return JSON.stringify(value);
|
4542
|
+
}
|
4543
|
+
try {
|
4544
|
+
return value.toString();
|
4545
|
+
} catch (e) {
|
4546
|
+
return value;
|
4547
|
+
}
|
4548
|
+
}
|
4549
|
+
function prepareParams(param1, param2) {
|
4550
|
+
if (isString(param1)) {
|
4551
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
4552
|
+
}
|
4553
|
+
if (isStringArray(param1)) {
|
4554
|
+
const statement = param1.reduce((acc, curr, index) => {
|
4555
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
4556
|
+
}, "");
|
4557
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
4558
|
+
}
|
4559
|
+
if (isObject(param1)) {
|
4560
|
+
const { statement, params, consistency } = param1;
|
4561
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
4562
|
+
}
|
4563
|
+
throw new Error("Invalid query");
|
4564
|
+
}
|
4565
|
+
|
4566
|
+
class SQLPlugin extends XataPlugin {
|
4567
|
+
build(pluginOptions) {
|
4568
|
+
return async (param1, ...param2) => {
|
4569
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
4570
|
+
const { records, warning } = await sqlQuery({
|
4571
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4572
|
+
body: { statement, params, consistency },
|
4573
|
+
...pluginOptions
|
4574
|
+
});
|
4575
|
+
return { records, warning };
|
4576
|
+
};
|
4577
|
+
}
|
4578
|
+
}
|
4579
|
+
|
4385
4580
|
class TransactionPlugin extends XataPlugin {
|
4386
4581
|
build(pluginOptions) {
|
4387
4582
|
return {
|
@@ -4397,12 +4592,6 @@ class TransactionPlugin extends XataPlugin {
|
|
4397
4592
|
}
|
4398
4593
|
}
|
4399
4594
|
|
4400
|
-
var __defProp$2 = Object.defineProperty;
|
4401
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4402
|
-
var __publicField$2 = (obj, key, value) => {
|
4403
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4404
|
-
return value;
|
4405
|
-
};
|
4406
4595
|
var __accessCheck = (obj, member, msg) => {
|
4407
4596
|
if (!member.has(obj))
|
4408
4597
|
throw TypeError("Cannot " + msg);
|
@@ -4432,10 +4621,6 @@ const buildClient = (plugins) => {
|
|
4432
4621
|
__privateAdd(this, _parseOptions);
|
4433
4622
|
__privateAdd(this, _getFetchProps);
|
4434
4623
|
__privateAdd(this, _options, void 0);
|
4435
|
-
__publicField$2(this, "db");
|
4436
|
-
__publicField$2(this, "search");
|
4437
|
-
__publicField$2(this, "transactions");
|
4438
|
-
__publicField$2(this, "files");
|
4439
4624
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
4440
4625
|
__privateSet(this, _options, safeOptions);
|
4441
4626
|
const pluginOptions = {
|
@@ -4446,10 +4631,12 @@ const buildClient = (plugins) => {
|
|
4446
4631
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
4447
4632
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
4448
4633
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4634
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
4449
4635
|
const files = new FilesPlugin().build(pluginOptions);
|
4450
4636
|
this.db = db;
|
4451
4637
|
this.search = search;
|
4452
4638
|
this.transactions = transactions;
|
4639
|
+
this.sql = sql;
|
4453
4640
|
this.files = files;
|
4454
4641
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
4455
4642
|
if (namespace === void 0)
|
@@ -4547,17 +4734,11 @@ const buildClient = (plugins) => {
|
|
4547
4734
|
class BaseClient extends buildClient() {
|
4548
4735
|
}
|
4549
4736
|
|
4550
|
-
var __defProp$1 = Object.defineProperty;
|
4551
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4552
|
-
var __publicField$1 = (obj, key, value) => {
|
4553
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4554
|
-
return value;
|
4555
|
-
};
|
4556
4737
|
const META = "__";
|
4557
4738
|
const VALUE = "___";
|
4558
4739
|
class Serializer {
|
4559
4740
|
constructor() {
|
4560
|
-
|
4741
|
+
this.classes = {};
|
4561
4742
|
}
|
4562
4743
|
add(clazz) {
|
4563
4744
|
this.classes[clazz.name] = clazz;
|
@@ -4620,37 +4801,16 @@ const deserialize = (json) => {
|
|
4620
4801
|
return defaultSerializer.fromJSON(json);
|
4621
4802
|
};
|
4622
4803
|
|
4623
|
-
function buildWorkerRunner(config) {
|
4624
|
-
return function xataWorker(name, worker) {
|
4625
|
-
return async (...args) => {
|
4626
|
-
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
4627
|
-
const result = await fetch(url, {
|
4628
|
-
method: "POST",
|
4629
|
-
headers: { "Content-Type": "application/json" },
|
4630
|
-
body: serialize({ args })
|
4631
|
-
});
|
4632
|
-
const text = await result.text();
|
4633
|
-
return deserialize(text);
|
4634
|
-
};
|
4635
|
-
};
|
4636
|
-
}
|
4637
|
-
|
4638
|
-
var __defProp = Object.defineProperty;
|
4639
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4640
|
-
var __publicField = (obj, key, value) => {
|
4641
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4642
|
-
return value;
|
4643
|
-
};
|
4644
4804
|
class XataError extends Error {
|
4645
4805
|
constructor(message, status) {
|
4646
4806
|
super(message);
|
4647
|
-
__publicField(this, "status");
|
4648
4807
|
this.status = status;
|
4649
4808
|
}
|
4650
4809
|
}
|
4651
4810
|
|
4652
4811
|
exports.BaseClient = BaseClient;
|
4653
4812
|
exports.FetcherError = FetcherError;
|
4813
|
+
exports.FilesPlugin = FilesPlugin;
|
4654
4814
|
exports.Operations = operationsByTag;
|
4655
4815
|
exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
|
4656
4816
|
exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
|
@@ -4662,10 +4822,12 @@ exports.RecordArray = RecordArray;
|
|
4662
4822
|
exports.RecordColumnTypes = RecordColumnTypes;
|
4663
4823
|
exports.Repository = Repository;
|
4664
4824
|
exports.RestRepository = RestRepository;
|
4825
|
+
exports.SQLPlugin = SQLPlugin;
|
4665
4826
|
exports.SchemaPlugin = SchemaPlugin;
|
4666
4827
|
exports.SearchPlugin = SearchPlugin;
|
4667
4828
|
exports.Serializer = Serializer;
|
4668
4829
|
exports.SimpleCache = SimpleCache;
|
4830
|
+
exports.TransactionPlugin = TransactionPlugin;
|
4669
4831
|
exports.XataApiClient = XataApiClient;
|
4670
4832
|
exports.XataApiPlugin = XataApiPlugin;
|
4671
4833
|
exports.XataError = XataError;
|
@@ -4676,13 +4838,13 @@ exports.addGitBranchesEntry = addGitBranchesEntry;
|
|
4676
4838
|
exports.addTableColumn = addTableColumn;
|
4677
4839
|
exports.aggregateTable = aggregateTable;
|
4678
4840
|
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
4841
|
+
exports.applyMigration = applyMigration;
|
4679
4842
|
exports.askTable = askTable;
|
4680
4843
|
exports.askTableSession = askTableSession;
|
4681
4844
|
exports.branchTransaction = branchTransaction;
|
4682
4845
|
exports.buildClient = buildClient;
|
4683
4846
|
exports.buildPreviewBranchName = buildPreviewBranchName;
|
4684
4847
|
exports.buildProviderString = buildProviderString;
|
4685
|
-
exports.buildWorkerRunner = buildWorkerRunner;
|
4686
4848
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
4687
4849
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
4688
4850
|
exports.compareBranchSchemas = compareBranchSchemas;
|
@@ -4691,6 +4853,7 @@ exports.compareMigrationRequest = compareMigrationRequest;
|
|
4691
4853
|
exports.contains = contains;
|
4692
4854
|
exports.copyBranch = copyBranch;
|
4693
4855
|
exports.createBranch = createBranch;
|
4856
|
+
exports.createCluster = createCluster;
|
4694
4857
|
exports.createDatabase = createDatabase;
|
4695
4858
|
exports.createMigrationRequest = createMigrationRequest;
|
4696
4859
|
exports.createTable = createTable;
|
@@ -4702,10 +4865,12 @@ exports.deleteDatabase = deleteDatabase;
|
|
4702
4865
|
exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
|
4703
4866
|
exports.deleteFile = deleteFile;
|
4704
4867
|
exports.deleteFileItem = deleteFileItem;
|
4868
|
+
exports.deleteOAuthAccessToken = deleteOAuthAccessToken;
|
4705
4869
|
exports.deleteRecord = deleteRecord;
|
4706
4870
|
exports.deleteTable = deleteTable;
|
4707
4871
|
exports.deleteUser = deleteUser;
|
4708
4872
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
4873
|
+
exports.deleteUserOAuthClient = deleteUserOAuthClient;
|
4709
4874
|
exports.deleteWorkspace = deleteWorkspace;
|
4710
4875
|
exports.deserialize = deserialize;
|
4711
4876
|
exports.endsWith = endsWith;
|
@@ -4713,9 +4878,10 @@ exports.equals = equals;
|
|
4713
4878
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
4714
4879
|
exports.exists = exists;
|
4715
4880
|
exports.fileAccess = fileAccess;
|
4881
|
+
exports.fileUpload = fileUpload;
|
4716
4882
|
exports.ge = ge;
|
4717
|
-
exports.generateAccessToken = generateAccessToken;
|
4718
4883
|
exports.getAPIKey = getAPIKey;
|
4884
|
+
exports.getAuthorizationCode = getAuthorizationCode;
|
4719
4885
|
exports.getBranch = getBranch;
|
4720
4886
|
exports.getBranchDetails = getBranchDetails;
|
4721
4887
|
exports.getBranchList = getBranchList;
|
@@ -4724,6 +4890,7 @@ exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
|
4724
4890
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
4725
4891
|
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
4726
4892
|
exports.getBranchStats = getBranchStats;
|
4893
|
+
exports.getCluster = getCluster;
|
4727
4894
|
exports.getColumn = getColumn;
|
4728
4895
|
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
4729
4896
|
exports.getDatabaseList = getDatabaseList;
|
@@ -4737,10 +4904,13 @@ exports.getMigrationRequest = getMigrationRequest;
|
|
4737
4904
|
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
4738
4905
|
exports.getPreviewBranch = getPreviewBranch;
|
4739
4906
|
exports.getRecord = getRecord;
|
4907
|
+
exports.getSchema = getSchema;
|
4740
4908
|
exports.getTableColumns = getTableColumns;
|
4741
4909
|
exports.getTableSchema = getTableSchema;
|
4742
4910
|
exports.getUser = getUser;
|
4743
4911
|
exports.getUserAPIKeys = getUserAPIKeys;
|
4912
|
+
exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
|
4913
|
+
exports.getUserOAuthClients = getUserOAuthClients;
|
4744
4914
|
exports.getWorkspace = getWorkspace;
|
4745
4915
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
4746
4916
|
exports.getWorkspacesList = getWorkspacesList;
|
@@ -4750,6 +4920,8 @@ exports.greaterThan = greaterThan;
|
|
4750
4920
|
exports.greaterThanEquals = greaterThanEquals;
|
4751
4921
|
exports.gt = gt;
|
4752
4922
|
exports.gte = gte;
|
4923
|
+
exports.iContains = iContains;
|
4924
|
+
exports.iPattern = iPattern;
|
4753
4925
|
exports.includes = includes;
|
4754
4926
|
exports.includesAll = includesAll;
|
4755
4927
|
exports.includesAny = includesAny;
|
@@ -4763,11 +4935,14 @@ exports.isHostProviderAlias = isHostProviderAlias;
|
|
4763
4935
|
exports.isHostProviderBuilder = isHostProviderBuilder;
|
4764
4936
|
exports.isIdentifiable = isIdentifiable;
|
4765
4937
|
exports.isNot = isNot;
|
4938
|
+
exports.isValidExpandedColumn = isValidExpandedColumn;
|
4939
|
+
exports.isValidSelectableColumns = isValidSelectableColumns;
|
4766
4940
|
exports.isXataRecord = isXataRecord;
|
4767
4941
|
exports.le = le;
|
4768
4942
|
exports.lessEquals = lessEquals;
|
4769
4943
|
exports.lessThan = lessThan;
|
4770
4944
|
exports.lessThanEquals = lessThanEquals;
|
4945
|
+
exports.listClusters = listClusters;
|
4771
4946
|
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
4772
4947
|
exports.listRegions = listRegions;
|
4773
4948
|
exports.lt = lt;
|
@@ -4778,6 +4953,9 @@ exports.operationsByTag = operationsByTag;
|
|
4778
4953
|
exports.parseProviderString = parseProviderString;
|
4779
4954
|
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
4780
4955
|
exports.pattern = pattern;
|
4956
|
+
exports.pgRollJobStatus = pgRollJobStatus;
|
4957
|
+
exports.pgRollMigrationHistory = pgRollMigrationHistory;
|
4958
|
+
exports.pgRollStatus = pgRollStatus;
|
4781
4959
|
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
4782
4960
|
exports.pushBranchMigrations = pushBranchMigrations;
|
4783
4961
|
exports.putFile = putFile;
|
@@ -4796,12 +4974,15 @@ exports.setTableSchema = setTableSchema;
|
|
4796
4974
|
exports.sqlQuery = sqlQuery;
|
4797
4975
|
exports.startsWith = startsWith;
|
4798
4976
|
exports.summarizeTable = summarizeTable;
|
4977
|
+
exports.transformImage = transformImage;
|
4799
4978
|
exports.updateBranchMetadata = updateBranchMetadata;
|
4800
4979
|
exports.updateBranchSchema = updateBranchSchema;
|
4980
|
+
exports.updateCluster = updateCluster;
|
4801
4981
|
exports.updateColumn = updateColumn;
|
4802
4982
|
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
4803
4983
|
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
4804
4984
|
exports.updateMigrationRequest = updateMigrationRequest;
|
4985
|
+
exports.updateOAuthAccessToken = updateOAuthAccessToken;
|
4805
4986
|
exports.updateRecordWithID = updateRecordWithID;
|
4806
4987
|
exports.updateTable = updateTable;
|
4807
4988
|
exports.updateUser = updateUser;
|