@xata.io/client 0.0.0-alpha.vfb0d929 → 0.0.0-alpha.vfb40563bcd4dc861559eae895dc85719e3688c57
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 -4
- package/CHANGELOG.md +125 -1
- package/dist/index.cjs +489 -322
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3162 -2482
- package/dist/index.mjs +473 -322
- 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;
|
@@ -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;
|
@@ -529,26 +528,16 @@ function defaultOnOpen(response) {
|
|
529
528
|
}
|
530
529
|
}
|
531
530
|
|
532
|
-
const VERSION = "0.
|
531
|
+
const VERSION = "0.28.4";
|
533
532
|
|
534
|
-
var __defProp$7 = Object.defineProperty;
|
535
|
-
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
536
|
-
var __publicField$7 = (obj, key, value) => {
|
537
|
-
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
538
|
-
return value;
|
539
|
-
};
|
540
533
|
class ErrorWithCause extends Error {
|
541
534
|
constructor(message, options) {
|
542
535
|
super(message, options);
|
543
|
-
__publicField$7(this, "cause");
|
544
536
|
}
|
545
537
|
}
|
546
538
|
class FetcherError extends ErrorWithCause {
|
547
539
|
constructor(status, data, requestId) {
|
548
540
|
super(getMessage(data));
|
549
|
-
__publicField$7(this, "status");
|
550
|
-
__publicField$7(this, "requestId");
|
551
|
-
__publicField$7(this, "errors");
|
552
541
|
this.status = status;
|
553
542
|
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
554
543
|
this.requestId = requestId;
|
@@ -582,6 +571,67 @@ function getMessage(data) {
|
|
582
571
|
}
|
583
572
|
}
|
584
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
|
+
|
585
635
|
const pool = new ApiRequestPool();
|
586
636
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
587
637
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
@@ -597,6 +647,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
597
647
|
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
598
648
|
};
|
599
649
|
function buildBaseUrl({
|
650
|
+
method,
|
600
651
|
endpoint,
|
601
652
|
path,
|
602
653
|
workspacesApiUrl,
|
@@ -604,7 +655,24 @@ function buildBaseUrl({
|
|
604
655
|
pathParams = {}
|
605
656
|
}) {
|
606
657
|
if (endpoint === "dataPlane") {
|
607
|
-
|
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
|
+
}
|
608
676
|
const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
|
609
677
|
return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
|
610
678
|
}
|
@@ -615,11 +683,14 @@ function hostHeader(url) {
|
|
615
683
|
const { groups } = pattern.exec(url) ?? {};
|
616
684
|
return groups?.host ? { Host: groups.host } : {};
|
617
685
|
}
|
618
|
-
function parseBody(body, headers) {
|
686
|
+
async function parseBody(body, headers) {
|
619
687
|
if (!isDefined(body))
|
620
688
|
return void 0;
|
689
|
+
if (isBlob(body) || typeof body.text === "function") {
|
690
|
+
return body;
|
691
|
+
}
|
621
692
|
const { "Content-Type": contentType } = headers ?? {};
|
622
|
-
if (String(contentType).toLowerCase() === "application/json") {
|
693
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
623
694
|
return JSON.stringify(body);
|
624
695
|
}
|
625
696
|
return body;
|
@@ -650,9 +721,9 @@ async function fetch$1({
|
|
650
721
|
return await trace(
|
651
722
|
`${method.toUpperCase()} ${path}`,
|
652
723
|
async ({ setAttributes }) => {
|
653
|
-
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
724
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
654
725
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
655
|
-
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
726
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\.[^.]+\./, "http://") : fullUrl;
|
656
727
|
setAttributes({
|
657
728
|
[TraceAttributes.HTTP_URL]: url,
|
658
729
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
@@ -676,7 +747,7 @@ async function fetch$1({
|
|
676
747
|
const response = await pool.request(url, {
|
677
748
|
...fetchOptions,
|
678
749
|
method: method.toUpperCase(),
|
679
|
-
body: parseBody(body, headers),
|
750
|
+
body: await parseBody(body, headers),
|
680
751
|
headers,
|
681
752
|
signal
|
682
753
|
});
|
@@ -687,7 +758,8 @@ async function fetch$1({
|
|
687
758
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
688
759
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
689
760
|
[TraceAttributes.HTTP_HOST]: host,
|
690
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
761
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
762
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
691
763
|
});
|
692
764
|
const message = response.headers?.get("x-xata-message");
|
693
765
|
if (message)
|
@@ -732,7 +804,7 @@ function fetchSSERequest({
|
|
732
804
|
clientName,
|
733
805
|
xataAgentExtra
|
734
806
|
}) {
|
735
|
-
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
807
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
736
808
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
737
809
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
738
810
|
void fetchEventSource(url, {
|
@@ -775,6 +847,20 @@ function parseUrl(url) {
|
|
775
847
|
|
776
848
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
777
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 });
|
778
864
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
779
865
|
url: "/dbs/{dbName}",
|
780
866
|
method: "get",
|
@@ -794,6 +880,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
794
880
|
...variables,
|
795
881
|
signal
|
796
882
|
});
|
883
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
884
|
+
url: "/db/{dbBranchName}/schema",
|
885
|
+
method: "get",
|
886
|
+
...variables,
|
887
|
+
signal
|
888
|
+
});
|
797
889
|
const copyBranch = (variables, signal) => dataPlaneFetch({
|
798
890
|
url: "/db/{dbBranchName}/copy",
|
799
891
|
method: "post",
|
@@ -975,6 +1067,12 @@ const fileAccess = (variables, signal) => dataPlaneFetch({
|
|
975
1067
|
...variables,
|
976
1068
|
signal
|
977
1069
|
});
|
1070
|
+
const fileUpload = (variables, signal) => dataPlaneFetch({
|
1071
|
+
url: "/file/{fileId}",
|
1072
|
+
method: "put",
|
1073
|
+
...variables,
|
1074
|
+
signal
|
1075
|
+
});
|
978
1076
|
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
979
1077
|
url: "/db/{dbBranchName}/sql",
|
980
1078
|
method: "post",
|
@@ -983,6 +1081,10 @@ const sqlQuery = (variables, signal) => dataPlaneFetch({
|
|
983
1081
|
});
|
984
1082
|
const operationsByTag$2 = {
|
985
1083
|
branch: {
|
1084
|
+
applyMigration,
|
1085
|
+
pgRollStatus,
|
1086
|
+
pgRollJobStatus,
|
1087
|
+
pgRollMigrationHistory,
|
986
1088
|
getBranchList,
|
987
1089
|
getBranchDetails,
|
988
1090
|
createBranch,
|
@@ -997,6 +1099,7 @@ const operationsByTag$2 = {
|
|
997
1099
|
resolveBranch
|
998
1100
|
},
|
999
1101
|
migrations: {
|
1102
|
+
getSchema,
|
1000
1103
|
getBranchMigrationHistory,
|
1001
1104
|
getBranchMigrationPlan,
|
1002
1105
|
executeBranchMigrationPlan,
|
@@ -1040,7 +1143,7 @@ const operationsByTag$2 = {
|
|
1040
1143
|
deleteRecord,
|
1041
1144
|
bulkInsertTableRecords
|
1042
1145
|
},
|
1043
|
-
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1146
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
|
1044
1147
|
searchAndFilter: {
|
1045
1148
|
queryTable,
|
1046
1149
|
searchBranch,
|
@@ -1100,6 +1203,12 @@ const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
|
1100
1203
|
...variables,
|
1101
1204
|
signal
|
1102
1205
|
});
|
1206
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1207
|
+
url: "/user/oauth/clients/{clientId}",
|
1208
|
+
method: "delete",
|
1209
|
+
...variables,
|
1210
|
+
signal
|
1211
|
+
});
|
1103
1212
|
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1104
1213
|
url: "/user/oauth/tokens",
|
1105
1214
|
method: "get",
|
@@ -1156,6 +1265,15 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
|
|
1156
1265
|
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
1157
1266
|
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
1158
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 });
|
1159
1277
|
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
1160
1278
|
url: "/workspaces/{workspaceId}/dbs",
|
1161
1279
|
method: "get",
|
@@ -1182,9 +1300,17 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
1182
1300
|
signal
|
1183
1301
|
});
|
1184
1302
|
const operationsByTag$1 = {
|
1185
|
-
|
1303
|
+
oAuth: {
|
1304
|
+
getAuthorizationCode,
|
1305
|
+
grantAuthorizationCode,
|
1306
|
+
getUserOAuthClients,
|
1307
|
+
deleteUserOAuthClient,
|
1308
|
+
getUserOAuthAccessTokens,
|
1309
|
+
deleteOAuthAccessToken,
|
1310
|
+
updateOAuthAccessToken
|
1311
|
+
},
|
1186
1312
|
users: { getUser, updateUser, deleteUser },
|
1187
|
-
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey
|
1313
|
+
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
1188
1314
|
workspaces: {
|
1189
1315
|
getWorkspacesList,
|
1190
1316
|
createWorkspace,
|
@@ -1202,6 +1328,7 @@ const operationsByTag$1 = {
|
|
1202
1328
|
acceptWorkspaceMemberInvite,
|
1203
1329
|
resendWorkspaceMemberInvite
|
1204
1330
|
},
|
1331
|
+
xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
|
1205
1332
|
databases: {
|
1206
1333
|
getDatabaseList,
|
1207
1334
|
createDatabase,
|
@@ -1218,61 +1345,6 @@ const operationsByTag$1 = {
|
|
1218
1345
|
|
1219
1346
|
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
1220
1347
|
|
1221
|
-
function getHostUrl(provider, type) {
|
1222
|
-
if (isHostProviderAlias(provider)) {
|
1223
|
-
return providers[provider][type];
|
1224
|
-
} else if (isHostProviderBuilder(provider)) {
|
1225
|
-
return provider[type];
|
1226
|
-
}
|
1227
|
-
throw new Error("Invalid API provider");
|
1228
|
-
}
|
1229
|
-
const providers = {
|
1230
|
-
production: {
|
1231
|
-
main: "https://api.xata.io",
|
1232
|
-
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
1233
|
-
},
|
1234
|
-
staging: {
|
1235
|
-
main: "https://api.staging-xata.dev",
|
1236
|
-
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1237
|
-
},
|
1238
|
-
dev: {
|
1239
|
-
main: "https://api.dev-xata.dev",
|
1240
|
-
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
1241
|
-
}
|
1242
|
-
};
|
1243
|
-
function isHostProviderAlias(alias) {
|
1244
|
-
return isString(alias) && Object.keys(providers).includes(alias);
|
1245
|
-
}
|
1246
|
-
function isHostProviderBuilder(builder) {
|
1247
|
-
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
1248
|
-
}
|
1249
|
-
function parseProviderString(provider = "production") {
|
1250
|
-
if (isHostProviderAlias(provider)) {
|
1251
|
-
return provider;
|
1252
|
-
}
|
1253
|
-
const [main, workspaces] = provider.split(",");
|
1254
|
-
if (!main || !workspaces)
|
1255
|
-
return null;
|
1256
|
-
return { main, workspaces };
|
1257
|
-
}
|
1258
|
-
function buildProviderString(provider) {
|
1259
|
-
if (isHostProviderAlias(provider))
|
1260
|
-
return provider;
|
1261
|
-
return `${provider.main},${provider.workspaces}`;
|
1262
|
-
}
|
1263
|
-
function parseWorkspacesUrlParts(url) {
|
1264
|
-
if (!isString(url))
|
1265
|
-
return null;
|
1266
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1267
|
-
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1268
|
-
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1269
|
-
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1270
|
-
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
1271
|
-
if (!match)
|
1272
|
-
return null;
|
1273
|
-
return { workspace: match[1], region: match[2] };
|
1274
|
-
}
|
1275
|
-
|
1276
1348
|
var __accessCheck$7 = (obj, member, msg) => {
|
1277
1349
|
if (!member.has(obj))
|
1278
1350
|
throw TypeError("Cannot " + msg);
|
@@ -2597,60 +2669,6 @@ class XataApiPlugin {
|
|
2597
2669
|
class XataPlugin {
|
2598
2670
|
}
|
2599
2671
|
|
2600
|
-
class FilesPlugin extends XataPlugin {
|
2601
|
-
build(pluginOptions) {
|
2602
|
-
return {
|
2603
|
-
download: async (location) => {
|
2604
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2605
|
-
return await getFileItem({
|
2606
|
-
pathParams: {
|
2607
|
-
workspace: "{workspaceId}",
|
2608
|
-
dbBranchName: "{dbBranch}",
|
2609
|
-
region: "{region}",
|
2610
|
-
tableName: table ?? "",
|
2611
|
-
recordId: record ?? "",
|
2612
|
-
columnName: column ?? "",
|
2613
|
-
fileId
|
2614
|
-
},
|
2615
|
-
...pluginOptions,
|
2616
|
-
rawResponse: true
|
2617
|
-
});
|
2618
|
-
},
|
2619
|
-
upload: async (location, file) => {
|
2620
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2621
|
-
return await putFileItem({
|
2622
|
-
pathParams: {
|
2623
|
-
workspace: "{workspaceId}",
|
2624
|
-
dbBranchName: "{dbBranch}",
|
2625
|
-
region: "{region}",
|
2626
|
-
tableName: table ?? "",
|
2627
|
-
recordId: record ?? "",
|
2628
|
-
columnName: column ?? "",
|
2629
|
-
fileId
|
2630
|
-
},
|
2631
|
-
body: file,
|
2632
|
-
...pluginOptions
|
2633
|
-
});
|
2634
|
-
},
|
2635
|
-
delete: async (location) => {
|
2636
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2637
|
-
return await deleteFileItem({
|
2638
|
-
pathParams: {
|
2639
|
-
workspace: "{workspaceId}",
|
2640
|
-
dbBranchName: "{dbBranch}",
|
2641
|
-
region: "{region}",
|
2642
|
-
tableName: table ?? "",
|
2643
|
-
recordId: record ?? "",
|
2644
|
-
columnName: column ?? "",
|
2645
|
-
fileId
|
2646
|
-
},
|
2647
|
-
...pluginOptions
|
2648
|
-
});
|
2649
|
-
}
|
2650
|
-
};
|
2651
|
-
}
|
2652
|
-
}
|
2653
|
-
|
2654
2672
|
function buildTransformString(transformations) {
|
2655
2673
|
return transformations.flatMap(
|
2656
2674
|
(t) => Object.entries(t).map(([key, value]) => {
|
@@ -2666,71 +2684,33 @@ function buildTransformString(transformations) {
|
|
2666
2684
|
})
|
2667
2685
|
).join(",");
|
2668
2686
|
}
|
2669
|
-
function transformImage(url, transformations) {
|
2687
|
+
function transformImage(url, ...transformations) {
|
2670
2688
|
if (!isDefined(url))
|
2671
2689
|
return void 0;
|
2672
|
-
const
|
2690
|
+
const newTransformations = buildTransformString(transformations);
|
2673
2691
|
const { hostname, pathname, search } = new URL(url);
|
2674
|
-
|
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}`;
|
2675
2698
|
}
|
2676
2699
|
|
2677
|
-
var __defProp$6 = Object.defineProperty;
|
2678
|
-
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2679
|
-
var __publicField$6 = (obj, key, value) => {
|
2680
|
-
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2681
|
-
return value;
|
2682
|
-
};
|
2683
2700
|
class XataFile {
|
2684
2701
|
constructor(file) {
|
2685
|
-
|
2686
|
-
* Name of this file.
|
2687
|
-
*/
|
2688
|
-
__publicField$6(this, "name");
|
2689
|
-
/**
|
2690
|
-
* Media type of this file.
|
2691
|
-
*/
|
2692
|
-
__publicField$6(this, "mediaType");
|
2693
|
-
/**
|
2694
|
-
* Base64 encoded content of this file.
|
2695
|
-
*/
|
2696
|
-
__publicField$6(this, "base64Content");
|
2697
|
-
/**
|
2698
|
-
* Whether to enable public url for this file.
|
2699
|
-
*/
|
2700
|
-
__publicField$6(this, "enablePublicUrl");
|
2701
|
-
/**
|
2702
|
-
* Timeout for the signed url.
|
2703
|
-
*/
|
2704
|
-
__publicField$6(this, "signedUrlTimeout");
|
2705
|
-
/**
|
2706
|
-
* Size of this file.
|
2707
|
-
*/
|
2708
|
-
__publicField$6(this, "size");
|
2709
|
-
/**
|
2710
|
-
* Version of this file.
|
2711
|
-
*/
|
2712
|
-
__publicField$6(this, "version");
|
2713
|
-
/**
|
2714
|
-
* Url of this file.
|
2715
|
-
*/
|
2716
|
-
__publicField$6(this, "url");
|
2717
|
-
/**
|
2718
|
-
* Signed url of this file.
|
2719
|
-
*/
|
2720
|
-
__publicField$6(this, "signedUrl");
|
2721
|
-
/**
|
2722
|
-
* Attributes of this file.
|
2723
|
-
*/
|
2724
|
-
__publicField$6(this, "attributes");
|
2702
|
+
this.id = file.id;
|
2725
2703
|
this.name = file.name;
|
2726
|
-
this.mediaType = file.mediaType
|
2704
|
+
this.mediaType = file.mediaType;
|
2727
2705
|
this.base64Content = file.base64Content;
|
2728
2706
|
this.enablePublicUrl = file.enablePublicUrl;
|
2729
2707
|
this.signedUrlTimeout = file.signedUrlTimeout;
|
2708
|
+
this.uploadUrlTimeout = file.uploadUrlTimeout;
|
2730
2709
|
this.size = file.size;
|
2731
2710
|
this.version = file.version;
|
2732
2711
|
this.url = file.url;
|
2733
2712
|
this.signedUrl = file.signedUrl;
|
2713
|
+
this.uploadUrl = file.uploadUrl;
|
2734
2714
|
this.attributes = file.attributes;
|
2735
2715
|
}
|
2736
2716
|
static fromBuffer(buffer, options = {}) {
|
@@ -2783,8 +2763,12 @@ class XataFile {
|
|
2783
2763
|
if (!this.base64Content) {
|
2784
2764
|
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2785
2765
|
}
|
2786
|
-
const
|
2787
|
-
|
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 });
|
2788
2772
|
}
|
2789
2773
|
static fromString(string, options = {}) {
|
2790
2774
|
const base64Content = btoa(string);
|
@@ -2807,16 +2791,27 @@ class XataFile {
|
|
2807
2791
|
}
|
2808
2792
|
transform(...options) {
|
2809
2793
|
return {
|
2810
|
-
url: transformImage(this.url, options),
|
2811
|
-
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" })
|
2812
2798
|
};
|
2813
2799
|
}
|
2814
2800
|
}
|
2815
2801
|
const parseInputFileEntry = async (entry) => {
|
2816
2802
|
if (!isDefined(entry))
|
2817
2803
|
return null;
|
2818
|
-
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2819
|
-
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
|
+
});
|
2820
2815
|
};
|
2821
2816
|
|
2822
2817
|
function cleanFilter(filter) {
|
@@ -2846,12 +2841,25 @@ function cleanFilter(filter) {
|
|
2846
2841
|
return Object.keys(values).length > 0 ? values : void 0;
|
2847
2842
|
}
|
2848
2843
|
|
2849
|
-
|
2850
|
-
|
2851
|
-
|
2852
|
-
|
2853
|
-
|
2854
|
-
|
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
|
+
|
2855
2863
|
var __accessCheck$6 = (obj, member, msg) => {
|
2856
2864
|
if (!member.has(obj))
|
2857
2865
|
throw TypeError("Cannot " + msg);
|
@@ -2874,14 +2882,6 @@ var _query, _page;
|
|
2874
2882
|
class Page {
|
2875
2883
|
constructor(query, meta, records = []) {
|
2876
2884
|
__privateAdd$6(this, _query, void 0);
|
2877
|
-
/**
|
2878
|
-
* Page metadata, required to retrieve additional records.
|
2879
|
-
*/
|
2880
|
-
__publicField$5(this, "meta");
|
2881
|
-
/**
|
2882
|
-
* The set of results for this page.
|
2883
|
-
*/
|
2884
|
-
__publicField$5(this, "records");
|
2885
2885
|
__privateSet$6(this, _query, query);
|
2886
2886
|
this.meta = meta;
|
2887
2887
|
this.records = new RecordArray(this, records);
|
@@ -2931,9 +2931,9 @@ class Page {
|
|
2931
2931
|
}
|
2932
2932
|
}
|
2933
2933
|
_query = new WeakMap();
|
2934
|
-
const PAGINATION_MAX_SIZE =
|
2934
|
+
const PAGINATION_MAX_SIZE = 1e3;
|
2935
2935
|
const PAGINATION_DEFAULT_SIZE = 20;
|
2936
|
-
const PAGINATION_MAX_OFFSET =
|
2936
|
+
const PAGINATION_MAX_OFFSET = 49e3;
|
2937
2937
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
2938
2938
|
function isCursorPaginationOptions(options) {
|
2939
2939
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
@@ -3012,12 +3012,6 @@ const _RecordArray = class _RecordArray extends Array {
|
|
3012
3012
|
_page = new WeakMap();
|
3013
3013
|
let RecordArray = _RecordArray;
|
3014
3014
|
|
3015
|
-
var __defProp$4 = Object.defineProperty;
|
3016
|
-
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
3017
|
-
var __publicField$4 = (obj, key, value) => {
|
3018
|
-
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
3019
|
-
return value;
|
3020
|
-
};
|
3021
3015
|
var __accessCheck$5 = (obj, member, msg) => {
|
3022
3016
|
if (!member.has(obj))
|
3023
3017
|
throw TypeError("Cannot " + msg);
|
@@ -3048,8 +3042,8 @@ const _Query = class _Query {
|
|
3048
3042
|
__privateAdd$5(this, _repository, void 0);
|
3049
3043
|
__privateAdd$5(this, _data, { filter: {} });
|
3050
3044
|
// Implements pagination
|
3051
|
-
|
3052
|
-
|
3045
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
3046
|
+
this.records = new RecordArray(this, []);
|
3053
3047
|
__privateSet$5(this, _table$1, table);
|
3054
3048
|
if (repository) {
|
3055
3049
|
__privateSet$5(this, _repository, repository);
|
@@ -3304,7 +3298,8 @@ const RecordColumnTypes = [
|
|
3304
3298
|
"datetime",
|
3305
3299
|
"vector",
|
3306
3300
|
"file[]",
|
3307
|
-
"file"
|
3301
|
+
"file",
|
3302
|
+
"json"
|
3308
3303
|
];
|
3309
3304
|
function isIdentifiable(x) {
|
3310
3305
|
return isObject(x) && isString(x?.id);
|
@@ -3315,6 +3310,24 @@ function isXataRecord(x) {
|
|
3315
3310
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
3316
3311
|
}
|
3317
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
|
+
|
3318
3331
|
function isSortFilterString(value) {
|
3319
3332
|
return isString(value);
|
3320
3333
|
}
|
@@ -3415,24 +3428,24 @@ class RestRepository extends Query {
|
|
3415
3428
|
if (a.length === 0)
|
3416
3429
|
return [];
|
3417
3430
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
3418
|
-
const columns =
|
3431
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3419
3432
|
const result = await this.read(ids, columns);
|
3420
3433
|
return result;
|
3421
3434
|
}
|
3422
3435
|
if (isString(a) && isObject(b)) {
|
3423
3436
|
if (a === "")
|
3424
3437
|
throw new Error("The id can't be empty");
|
3425
|
-
const columns =
|
3438
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3426
3439
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
3427
3440
|
}
|
3428
3441
|
if (isObject(a) && isString(a.id)) {
|
3429
3442
|
if (a.id === "")
|
3430
3443
|
throw new Error("The id can't be empty");
|
3431
|
-
const columns =
|
3444
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3432
3445
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
3433
3446
|
}
|
3434
3447
|
if (isObject(a)) {
|
3435
|
-
const columns =
|
3448
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3436
3449
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
3437
3450
|
}
|
3438
3451
|
throw new Error("Invalid arguments for create method");
|
@@ -3440,7 +3453,7 @@ class RestRepository extends Query {
|
|
3440
3453
|
}
|
3441
3454
|
async read(a, b) {
|
3442
3455
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
3443
|
-
const columns =
|
3456
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3444
3457
|
if (Array.isArray(a)) {
|
3445
3458
|
if (a.length === 0)
|
3446
3459
|
return [];
|
@@ -3467,7 +3480,13 @@ class RestRepository extends Query {
|
|
3467
3480
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3468
3481
|
});
|
3469
3482
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3470
|
-
return initObject(
|
3483
|
+
return initObject(
|
3484
|
+
__privateGet$4(this, _db),
|
3485
|
+
schemaTables,
|
3486
|
+
__privateGet$4(this, _table),
|
3487
|
+
response,
|
3488
|
+
columns
|
3489
|
+
);
|
3471
3490
|
} catch (e) {
|
3472
3491
|
if (isObject(e) && e.status === 404) {
|
3473
3492
|
return null;
|
@@ -3509,17 +3528,17 @@ class RestRepository extends Query {
|
|
3509
3528
|
ifVersion,
|
3510
3529
|
upsert: false
|
3511
3530
|
});
|
3512
|
-
const columns =
|
3531
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3513
3532
|
const result = await this.read(a, columns);
|
3514
3533
|
return result;
|
3515
3534
|
}
|
3516
3535
|
try {
|
3517
3536
|
if (isString(a) && isObject(b)) {
|
3518
|
-
const columns =
|
3537
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3519
3538
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3520
3539
|
}
|
3521
3540
|
if (isObject(a) && isString(a.id)) {
|
3522
|
-
const columns =
|
3541
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3523
3542
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3524
3543
|
}
|
3525
3544
|
} catch (error) {
|
@@ -3559,20 +3578,20 @@ class RestRepository extends Query {
|
|
3559
3578
|
ifVersion,
|
3560
3579
|
upsert: true
|
3561
3580
|
});
|
3562
|
-
const columns =
|
3581
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3563
3582
|
const result = await this.read(a, columns);
|
3564
3583
|
return result;
|
3565
3584
|
}
|
3566
3585
|
if (isString(a) && isObject(b)) {
|
3567
3586
|
if (a === "")
|
3568
3587
|
throw new Error("The id can't be empty");
|
3569
|
-
const columns =
|
3588
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3570
3589
|
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3571
3590
|
}
|
3572
3591
|
if (isObject(a) && isString(a.id)) {
|
3573
3592
|
if (a.id === "")
|
3574
3593
|
throw new Error("The id can't be empty");
|
3575
|
-
const columns =
|
3594
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3576
3595
|
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3577
3596
|
}
|
3578
3597
|
if (!isDefined(a) && isObject(b)) {
|
@@ -3591,20 +3610,20 @@ class RestRepository extends Query {
|
|
3591
3610
|
if (a.length === 0)
|
3592
3611
|
return [];
|
3593
3612
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
3594
|
-
const columns =
|
3613
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3595
3614
|
const result = await this.read(ids, columns);
|
3596
3615
|
return result;
|
3597
3616
|
}
|
3598
3617
|
if (isString(a) && isObject(b)) {
|
3599
3618
|
if (a === "")
|
3600
3619
|
throw new Error("The id can't be empty");
|
3601
|
-
const columns =
|
3620
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3602
3621
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3603
3622
|
}
|
3604
3623
|
if (isObject(a) && isString(a.id)) {
|
3605
3624
|
if (a.id === "")
|
3606
3625
|
throw new Error("The id can't be empty");
|
3607
|
-
const columns =
|
3626
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3608
3627
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3609
3628
|
}
|
3610
3629
|
if (!isDefined(a) && isObject(b)) {
|
@@ -3628,7 +3647,7 @@ class RestRepository extends Query {
|
|
3628
3647
|
return o.id;
|
3629
3648
|
throw new Error("Invalid arguments for delete method");
|
3630
3649
|
});
|
3631
|
-
const columns =
|
3650
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3632
3651
|
const result = await this.read(a, columns);
|
3633
3652
|
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
3634
3653
|
return result;
|
@@ -3662,7 +3681,7 @@ class RestRepository extends Query {
|
|
3662
3681
|
}
|
3663
3682
|
async search(query, options = {}) {
|
3664
3683
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
3665
|
-
const { records } = await searchTable({
|
3684
|
+
const { records, totalCount } = await searchTable({
|
3666
3685
|
pathParams: {
|
3667
3686
|
workspace: "{workspaceId}",
|
3668
3687
|
dbBranchName: "{dbBranch}",
|
@@ -3682,12 +3701,15 @@ class RestRepository extends Query {
|
|
3682
3701
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3683
3702
|
});
|
3684
3703
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3685
|
-
return
|
3704
|
+
return {
|
3705
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3706
|
+
totalCount
|
3707
|
+
};
|
3686
3708
|
});
|
3687
3709
|
}
|
3688
3710
|
async vectorSearch(column, query, options) {
|
3689
3711
|
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3690
|
-
const { records } = await vectorSearchTable({
|
3712
|
+
const { records, totalCount } = await vectorSearchTable({
|
3691
3713
|
pathParams: {
|
3692
3714
|
workspace: "{workspaceId}",
|
3693
3715
|
dbBranchName: "{dbBranch}",
|
@@ -3704,7 +3726,10 @@ class RestRepository extends Query {
|
|
3704
3726
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3705
3727
|
});
|
3706
3728
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3707
|
-
return
|
3729
|
+
return {
|
3730
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3731
|
+
totalCount
|
3732
|
+
};
|
3708
3733
|
});
|
3709
3734
|
}
|
3710
3735
|
async aggregate(aggs, filter) {
|
@@ -3747,7 +3772,13 @@ class RestRepository extends Query {
|
|
3747
3772
|
});
|
3748
3773
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3749
3774
|
const records = objects.map(
|
3750
|
-
(record) => initObject(
|
3775
|
+
(record) => initObject(
|
3776
|
+
__privateGet$4(this, _db),
|
3777
|
+
schemaTables,
|
3778
|
+
__privateGet$4(this, _table),
|
3779
|
+
record,
|
3780
|
+
data.columns ?? ["*"]
|
3781
|
+
)
|
3751
3782
|
);
|
3752
3783
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
3753
3784
|
return new Page(query, meta, records);
|
@@ -3774,7 +3805,13 @@ class RestRepository extends Query {
|
|
3774
3805
|
},
|
3775
3806
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3776
3807
|
});
|
3777
|
-
|
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
|
+
};
|
3778
3815
|
});
|
3779
3816
|
}
|
3780
3817
|
ask(question, options) {
|
@@ -4053,19 +4090,15 @@ transformObjectToApi_fn = async function(object) {
|
|
4053
4090
|
case "file[]":
|
4054
4091
|
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4055
4092
|
break;
|
4093
|
+
case "json":
|
4094
|
+
result[key] = stringifyJson(value);
|
4095
|
+
break;
|
4056
4096
|
default:
|
4057
4097
|
result[key] = value;
|
4058
4098
|
}
|
4059
4099
|
}
|
4060
4100
|
return result;
|
4061
4101
|
};
|
4062
|
-
const removeLinksFromObject = (object) => {
|
4063
|
-
return Object.entries(object).reduce((acc, [key, value]) => {
|
4064
|
-
if (key === "xata")
|
4065
|
-
return acc;
|
4066
|
-
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
4067
|
-
}, {});
|
4068
|
-
};
|
4069
4102
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
4070
4103
|
const data = {};
|
4071
4104
|
const { xata, ...rest } = object ?? {};
|
@@ -4096,13 +4129,19 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4096
4129
|
if (item === column.name) {
|
4097
4130
|
return [...acc, "*"];
|
4098
4131
|
}
|
4099
|
-
if (item.startsWith(`${column.name}.`)) {
|
4132
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
4100
4133
|
const [, ...path] = item.split(".");
|
4101
4134
|
return [...acc, path.join(".")];
|
4102
4135
|
}
|
4103
4136
|
return acc;
|
4104
4137
|
}, []);
|
4105
|
-
data[column.name] = initObject(
|
4138
|
+
data[column.name] = initObject(
|
4139
|
+
db,
|
4140
|
+
schemaTables,
|
4141
|
+
linkTable,
|
4142
|
+
value,
|
4143
|
+
selectedLinkColumns
|
4144
|
+
);
|
4106
4145
|
} else {
|
4107
4146
|
data[column.name] = null;
|
4108
4147
|
}
|
@@ -4114,6 +4153,9 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4114
4153
|
case "file[]":
|
4115
4154
|
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4116
4155
|
break;
|
4156
|
+
case "json":
|
4157
|
+
data[column.name] = parseJson(value);
|
4158
|
+
break;
|
4117
4159
|
default:
|
4118
4160
|
data[column.name] = value ?? null;
|
4119
4161
|
if (column.notNull === true && value === null) {
|
@@ -4123,33 +4165,34 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4123
4165
|
}
|
4124
4166
|
}
|
4125
4167
|
const record = { ...data };
|
4126
|
-
const serializable = { xata, ...removeLinksFromObject(data) };
|
4127
4168
|
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
4128
4169
|
record.read = function(columns2) {
|
4129
4170
|
return db[table].read(record["id"], columns2);
|
4130
4171
|
};
|
4131
4172
|
record.update = function(data2, b, c) {
|
4132
|
-
const columns2 =
|
4173
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
4133
4174
|
const ifVersion = parseIfVersion(b, c);
|
4134
4175
|
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
4135
4176
|
};
|
4136
4177
|
record.replace = function(data2, b, c) {
|
4137
|
-
const columns2 =
|
4178
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
4138
4179
|
const ifVersion = parseIfVersion(b, c);
|
4139
4180
|
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
4140
4181
|
};
|
4141
4182
|
record.delete = function() {
|
4142
4183
|
return db[table].delete(record["id"]);
|
4143
4184
|
};
|
4144
|
-
|
4185
|
+
if (metadata !== void 0) {
|
4186
|
+
record.xata = Object.freeze(metadata);
|
4187
|
+
}
|
4145
4188
|
record.getMetadata = function() {
|
4146
4189
|
return record.xata;
|
4147
4190
|
};
|
4148
4191
|
record.toSerializable = function() {
|
4149
|
-
return JSON.parse(JSON.stringify(
|
4192
|
+
return JSON.parse(JSON.stringify(record));
|
4150
4193
|
};
|
4151
4194
|
record.toString = function() {
|
4152
|
-
return JSON.stringify(
|
4195
|
+
return JSON.stringify(record);
|
4153
4196
|
};
|
4154
4197
|
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
4155
4198
|
Object.defineProperty(record, prop, { enumerable: false });
|
@@ -4167,7 +4210,7 @@ function extractId(value) {
|
|
4167
4210
|
function isValidColumn(columns, column) {
|
4168
4211
|
if (columns.includes("*"))
|
4169
4212
|
return true;
|
4170
|
-
return columns.filter((item) => item.startsWith(column.name)).length > 0;
|
4213
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
4171
4214
|
}
|
4172
4215
|
function parseIfVersion(...args) {
|
4173
4216
|
for (const arg of args) {
|
@@ -4178,12 +4221,6 @@ function parseIfVersion(...args) {
|
|
4178
4221
|
return void 0;
|
4179
4222
|
}
|
4180
4223
|
|
4181
|
-
var __defProp$3 = Object.defineProperty;
|
4182
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4183
|
-
var __publicField$3 = (obj, key, value) => {
|
4184
|
-
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4185
|
-
return value;
|
4186
|
-
};
|
4187
4224
|
var __accessCheck$3 = (obj, member, msg) => {
|
4188
4225
|
if (!member.has(obj))
|
4189
4226
|
throw TypeError("Cannot " + msg);
|
@@ -4206,8 +4243,6 @@ var _map;
|
|
4206
4243
|
class SimpleCache {
|
4207
4244
|
constructor(options = {}) {
|
4208
4245
|
__privateAdd$3(this, _map, void 0);
|
4209
|
-
__publicField$3(this, "capacity");
|
4210
|
-
__publicField$3(this, "defaultQueryTTL");
|
4211
4246
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
4212
4247
|
this.capacity = options.max ?? 500;
|
4213
4248
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
@@ -4252,10 +4287,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
4252
4287
|
const startsWith = (value) => ({ $startsWith: value });
|
4253
4288
|
const endsWith = (value) => ({ $endsWith: value });
|
4254
4289
|
const pattern = (value) => ({ $pattern: value });
|
4290
|
+
const iPattern = (value) => ({ $iPattern: value });
|
4255
4291
|
const is = (value) => ({ $is: value });
|
4256
4292
|
const equals = is;
|
4257
4293
|
const isNot = (value) => ({ $isNot: value });
|
4258
4294
|
const contains = (value) => ({ $contains: value });
|
4295
|
+
const iContains = (value) => ({ $iContains: value });
|
4259
4296
|
const includes = (value) => ({ $includes: value });
|
4260
4297
|
const includesAll = (value) => ({ $includesAll: value });
|
4261
4298
|
const includesNone = (value) => ({ $includesNone: value });
|
@@ -4311,6 +4348,80 @@ class SchemaPlugin extends XataPlugin {
|
|
4311
4348
|
_tables = new WeakMap();
|
4312
4349
|
_schemaTables$1 = new WeakMap();
|
4313
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
|
+
|
4314
4425
|
var __accessCheck$1 = (obj, member, msg) => {
|
4315
4426
|
if (!member.has(obj))
|
4316
4427
|
throw TypeError("Cannot " + msg);
|
@@ -4346,22 +4457,26 @@ class SearchPlugin extends XataPlugin {
|
|
4346
4457
|
build(pluginOptions) {
|
4347
4458
|
return {
|
4348
4459
|
all: async (query, options = {}) => {
|
4349
|
-
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);
|
4350
4461
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4351
|
-
return
|
4352
|
-
|
4353
|
-
|
4354
|
-
|
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
|
+
};
|
4355
4469
|
},
|
4356
4470
|
byTable: async (query, options = {}) => {
|
4357
|
-
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);
|
4358
4472
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4359
|
-
|
4473
|
+
const records = rawRecords.reduce((acc, record) => {
|
4360
4474
|
const { table = "orphan" } = record.xata;
|
4361
4475
|
const items = acc[table] ?? [];
|
4362
4476
|
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
4363
4477
|
return { ...acc, [table]: [...items, item] };
|
4364
4478
|
}, {});
|
4479
|
+
return { totalCount, records };
|
4365
4480
|
}
|
4366
4481
|
};
|
4367
4482
|
}
|
@@ -4370,13 +4485,13 @@ _schemaTables = new WeakMap();
|
|
4370
4485
|
_search = new WeakSet();
|
4371
4486
|
search_fn = async function(query, options, pluginOptions) {
|
4372
4487
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
4373
|
-
const { records } = await searchBranch({
|
4488
|
+
const { records, totalCount } = await searchBranch({
|
4374
4489
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4375
4490
|
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
4376
4491
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
4377
4492
|
...pluginOptions
|
4378
4493
|
});
|
4379
|
-
return records;
|
4494
|
+
return { records, totalCount };
|
4380
4495
|
};
|
4381
4496
|
_getSchemaTables = new WeakSet();
|
4382
4497
|
getSchemaTables_fn = async function(pluginOptions) {
|
@@ -4390,6 +4505,78 @@ getSchemaTables_fn = async function(pluginOptions) {
|
|
4390
4505
|
return schema.tables;
|
4391
4506
|
};
|
4392
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
|
+
|
4393
4580
|
class TransactionPlugin extends XataPlugin {
|
4394
4581
|
build(pluginOptions) {
|
4395
4582
|
return {
|
@@ -4405,12 +4592,6 @@ class TransactionPlugin extends XataPlugin {
|
|
4405
4592
|
}
|
4406
4593
|
}
|
4407
4594
|
|
4408
|
-
var __defProp$2 = Object.defineProperty;
|
4409
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4410
|
-
var __publicField$2 = (obj, key, value) => {
|
4411
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4412
|
-
return value;
|
4413
|
-
};
|
4414
4595
|
var __accessCheck = (obj, member, msg) => {
|
4415
4596
|
if (!member.has(obj))
|
4416
4597
|
throw TypeError("Cannot " + msg);
|
@@ -4440,10 +4621,6 @@ const buildClient = (plugins) => {
|
|
4440
4621
|
__privateAdd(this, _parseOptions);
|
4441
4622
|
__privateAdd(this, _getFetchProps);
|
4442
4623
|
__privateAdd(this, _options, void 0);
|
4443
|
-
__publicField$2(this, "db");
|
4444
|
-
__publicField$2(this, "search");
|
4445
|
-
__publicField$2(this, "transactions");
|
4446
|
-
__publicField$2(this, "files");
|
4447
4624
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
4448
4625
|
__privateSet(this, _options, safeOptions);
|
4449
4626
|
const pluginOptions = {
|
@@ -4454,10 +4631,12 @@ const buildClient = (plugins) => {
|
|
4454
4631
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
4455
4632
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
4456
4633
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4634
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
4457
4635
|
const files = new FilesPlugin().build(pluginOptions);
|
4458
4636
|
this.db = db;
|
4459
4637
|
this.search = search;
|
4460
4638
|
this.transactions = transactions;
|
4639
|
+
this.sql = sql;
|
4461
4640
|
this.files = files;
|
4462
4641
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
4463
4642
|
if (namespace === void 0)
|
@@ -4555,17 +4734,11 @@ const buildClient = (plugins) => {
|
|
4555
4734
|
class BaseClient extends buildClient() {
|
4556
4735
|
}
|
4557
4736
|
|
4558
|
-
var __defProp$1 = Object.defineProperty;
|
4559
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4560
|
-
var __publicField$1 = (obj, key, value) => {
|
4561
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4562
|
-
return value;
|
4563
|
-
};
|
4564
4737
|
const META = "__";
|
4565
4738
|
const VALUE = "___";
|
4566
4739
|
class Serializer {
|
4567
4740
|
constructor() {
|
4568
|
-
|
4741
|
+
this.classes = {};
|
4569
4742
|
}
|
4570
4743
|
add(clazz) {
|
4571
4744
|
this.classes[clazz.name] = clazz;
|
@@ -4628,31 +4801,9 @@ const deserialize = (json) => {
|
|
4628
4801
|
return defaultSerializer.fromJSON(json);
|
4629
4802
|
};
|
4630
4803
|
|
4631
|
-
function buildWorkerRunner(config) {
|
4632
|
-
return function xataWorker(name, worker) {
|
4633
|
-
return async (...args) => {
|
4634
|
-
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
4635
|
-
const result = await fetch(url, {
|
4636
|
-
method: "POST",
|
4637
|
-
headers: { "Content-Type": "application/json" },
|
4638
|
-
body: serialize({ args })
|
4639
|
-
});
|
4640
|
-
const text = await result.text();
|
4641
|
-
return deserialize(text);
|
4642
|
-
};
|
4643
|
-
};
|
4644
|
-
}
|
4645
|
-
|
4646
|
-
var __defProp = Object.defineProperty;
|
4647
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4648
|
-
var __publicField = (obj, key, value) => {
|
4649
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4650
|
-
return value;
|
4651
|
-
};
|
4652
4804
|
class XataError extends Error {
|
4653
4805
|
constructor(message, status) {
|
4654
4806
|
super(message);
|
4655
|
-
__publicField(this, "status");
|
4656
4807
|
this.status = status;
|
4657
4808
|
}
|
4658
4809
|
}
|
@@ -4671,10 +4822,12 @@ exports.RecordArray = RecordArray;
|
|
4671
4822
|
exports.RecordColumnTypes = RecordColumnTypes;
|
4672
4823
|
exports.Repository = Repository;
|
4673
4824
|
exports.RestRepository = RestRepository;
|
4825
|
+
exports.SQLPlugin = SQLPlugin;
|
4674
4826
|
exports.SchemaPlugin = SchemaPlugin;
|
4675
4827
|
exports.SearchPlugin = SearchPlugin;
|
4676
4828
|
exports.Serializer = Serializer;
|
4677
4829
|
exports.SimpleCache = SimpleCache;
|
4830
|
+
exports.TransactionPlugin = TransactionPlugin;
|
4678
4831
|
exports.XataApiClient = XataApiClient;
|
4679
4832
|
exports.XataApiPlugin = XataApiPlugin;
|
4680
4833
|
exports.XataError = XataError;
|
@@ -4685,13 +4838,13 @@ exports.addGitBranchesEntry = addGitBranchesEntry;
|
|
4685
4838
|
exports.addTableColumn = addTableColumn;
|
4686
4839
|
exports.aggregateTable = aggregateTable;
|
4687
4840
|
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
4841
|
+
exports.applyMigration = applyMigration;
|
4688
4842
|
exports.askTable = askTable;
|
4689
4843
|
exports.askTableSession = askTableSession;
|
4690
4844
|
exports.branchTransaction = branchTransaction;
|
4691
4845
|
exports.buildClient = buildClient;
|
4692
4846
|
exports.buildPreviewBranchName = buildPreviewBranchName;
|
4693
4847
|
exports.buildProviderString = buildProviderString;
|
4694
|
-
exports.buildWorkerRunner = buildWorkerRunner;
|
4695
4848
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
4696
4849
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
4697
4850
|
exports.compareBranchSchemas = compareBranchSchemas;
|
@@ -4700,6 +4853,7 @@ exports.compareMigrationRequest = compareMigrationRequest;
|
|
4700
4853
|
exports.contains = contains;
|
4701
4854
|
exports.copyBranch = copyBranch;
|
4702
4855
|
exports.createBranch = createBranch;
|
4856
|
+
exports.createCluster = createCluster;
|
4703
4857
|
exports.createDatabase = createDatabase;
|
4704
4858
|
exports.createMigrationRequest = createMigrationRequest;
|
4705
4859
|
exports.createTable = createTable;
|
@@ -4716,6 +4870,7 @@ exports.deleteRecord = deleteRecord;
|
|
4716
4870
|
exports.deleteTable = deleteTable;
|
4717
4871
|
exports.deleteUser = deleteUser;
|
4718
4872
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
4873
|
+
exports.deleteUserOAuthClient = deleteUserOAuthClient;
|
4719
4874
|
exports.deleteWorkspace = deleteWorkspace;
|
4720
4875
|
exports.deserialize = deserialize;
|
4721
4876
|
exports.endsWith = endsWith;
|
@@ -4723,6 +4878,7 @@ exports.equals = equals;
|
|
4723
4878
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
4724
4879
|
exports.exists = exists;
|
4725
4880
|
exports.fileAccess = fileAccess;
|
4881
|
+
exports.fileUpload = fileUpload;
|
4726
4882
|
exports.ge = ge;
|
4727
4883
|
exports.getAPIKey = getAPIKey;
|
4728
4884
|
exports.getAuthorizationCode = getAuthorizationCode;
|
@@ -4734,6 +4890,7 @@ exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
|
4734
4890
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
4735
4891
|
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
4736
4892
|
exports.getBranchStats = getBranchStats;
|
4893
|
+
exports.getCluster = getCluster;
|
4737
4894
|
exports.getColumn = getColumn;
|
4738
4895
|
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
4739
4896
|
exports.getDatabaseList = getDatabaseList;
|
@@ -4747,6 +4904,7 @@ exports.getMigrationRequest = getMigrationRequest;
|
|
4747
4904
|
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
4748
4905
|
exports.getPreviewBranch = getPreviewBranch;
|
4749
4906
|
exports.getRecord = getRecord;
|
4907
|
+
exports.getSchema = getSchema;
|
4750
4908
|
exports.getTableColumns = getTableColumns;
|
4751
4909
|
exports.getTableSchema = getTableSchema;
|
4752
4910
|
exports.getUser = getUser;
|
@@ -4762,6 +4920,8 @@ exports.greaterThan = greaterThan;
|
|
4762
4920
|
exports.greaterThanEquals = greaterThanEquals;
|
4763
4921
|
exports.gt = gt;
|
4764
4922
|
exports.gte = gte;
|
4923
|
+
exports.iContains = iContains;
|
4924
|
+
exports.iPattern = iPattern;
|
4765
4925
|
exports.includes = includes;
|
4766
4926
|
exports.includesAll = includesAll;
|
4767
4927
|
exports.includesAny = includesAny;
|
@@ -4775,11 +4935,14 @@ exports.isHostProviderAlias = isHostProviderAlias;
|
|
4775
4935
|
exports.isHostProviderBuilder = isHostProviderBuilder;
|
4776
4936
|
exports.isIdentifiable = isIdentifiable;
|
4777
4937
|
exports.isNot = isNot;
|
4938
|
+
exports.isValidExpandedColumn = isValidExpandedColumn;
|
4939
|
+
exports.isValidSelectableColumns = isValidSelectableColumns;
|
4778
4940
|
exports.isXataRecord = isXataRecord;
|
4779
4941
|
exports.le = le;
|
4780
4942
|
exports.lessEquals = lessEquals;
|
4781
4943
|
exports.lessThan = lessThan;
|
4782
4944
|
exports.lessThanEquals = lessThanEquals;
|
4945
|
+
exports.listClusters = listClusters;
|
4783
4946
|
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
4784
4947
|
exports.listRegions = listRegions;
|
4785
4948
|
exports.lt = lt;
|
@@ -4790,6 +4953,9 @@ exports.operationsByTag = operationsByTag;
|
|
4790
4953
|
exports.parseProviderString = parseProviderString;
|
4791
4954
|
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
4792
4955
|
exports.pattern = pattern;
|
4956
|
+
exports.pgRollJobStatus = pgRollJobStatus;
|
4957
|
+
exports.pgRollMigrationHistory = pgRollMigrationHistory;
|
4958
|
+
exports.pgRollStatus = pgRollStatus;
|
4793
4959
|
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
4794
4960
|
exports.pushBranchMigrations = pushBranchMigrations;
|
4795
4961
|
exports.putFile = putFile;
|
@@ -4811,6 +4977,7 @@ exports.summarizeTable = summarizeTable;
|
|
4811
4977
|
exports.transformImage = transformImage;
|
4812
4978
|
exports.updateBranchMetadata = updateBranchMetadata;
|
4813
4979
|
exports.updateBranchSchema = updateBranchSchema;
|
4980
|
+
exports.updateCluster = updateCluster;
|
4814
4981
|
exports.updateColumn = updateColumn;
|
4815
4982
|
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
4816
4983
|
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|