@xata.io/client 0.0.0-alpha.vf3ab3ad → 0.0.0-alpha.vf455e66cda21d00ed37168f3b02730a799f48650
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 +65 -1
- package/dist/index.cjs +509 -373
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3414 -2725
- package/dist/index.mjs +499 -373
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -248,7 +248,7 @@ var __accessCheck$8 = (obj, member, msg) => {
|
|
248
248
|
if (!member.has(obj))
|
249
249
|
throw TypeError("Cannot " + msg);
|
250
250
|
};
|
251
|
-
var __privateGet$
|
251
|
+
var __privateGet$7 = (obj, member, getter) => {
|
252
252
|
__accessCheck$8(obj, member, "read from private field");
|
253
253
|
return getter ? getter.call(obj) : member.get(obj);
|
254
254
|
};
|
@@ -257,7 +257,7 @@ var __privateAdd$8 = (obj, member, value) => {
|
|
257
257
|
throw TypeError("Cannot add the same private member more than once");
|
258
258
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
259
259
|
};
|
260
|
-
var __privateSet$
|
260
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
261
261
|
__accessCheck$8(obj, member, "write to private field");
|
262
262
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
263
263
|
return value;
|
@@ -283,19 +283,19 @@ class ApiRequestPool {
|
|
283
283
|
__privateAdd$8(this, _fetch, void 0);
|
284
284
|
__privateAdd$8(this, _queue, void 0);
|
285
285
|
__privateAdd$8(this, _concurrency, void 0);
|
286
|
-
__privateSet$
|
287
|
-
__privateSet$
|
286
|
+
__privateSet$6(this, _queue, []);
|
287
|
+
__privateSet$6(this, _concurrency, concurrency);
|
288
288
|
this.running = 0;
|
289
289
|
this.started = 0;
|
290
290
|
}
|
291
291
|
setFetch(fetch2) {
|
292
|
-
__privateSet$
|
292
|
+
__privateSet$6(this, _fetch, fetch2);
|
293
293
|
}
|
294
294
|
getFetch() {
|
295
|
-
if (!__privateGet$
|
295
|
+
if (!__privateGet$7(this, _fetch)) {
|
296
296
|
throw new Error("Fetch not set");
|
297
297
|
}
|
298
|
-
return __privateGet$
|
298
|
+
return __privateGet$7(this, _fetch);
|
299
299
|
}
|
300
300
|
request(url, options) {
|
301
301
|
const start = /* @__PURE__ */ new Date();
|
@@ -327,19 +327,19 @@ _queue = new WeakMap();
|
|
327
327
|
_concurrency = new WeakMap();
|
328
328
|
_enqueue = new WeakSet();
|
329
329
|
enqueue_fn = function(task) {
|
330
|
-
const promise = new Promise((resolve) => __privateGet$
|
330
|
+
const promise = new Promise((resolve) => __privateGet$7(this, _queue).push(resolve)).finally(() => {
|
331
331
|
this.started--;
|
332
332
|
this.running++;
|
333
333
|
}).then(() => task()).finally(() => {
|
334
334
|
this.running--;
|
335
|
-
const next = __privateGet$
|
335
|
+
const next = __privateGet$7(this, _queue).shift();
|
336
336
|
if (next !== void 0) {
|
337
337
|
this.started++;
|
338
338
|
next();
|
339
339
|
}
|
340
340
|
});
|
341
|
-
if (this.running + this.started < __privateGet$
|
342
|
-
const next = __privateGet$
|
341
|
+
if (this.running + this.started < __privateGet$7(this, _concurrency)) {
|
342
|
+
const next = __privateGet$7(this, _queue).shift();
|
343
343
|
if (next !== void 0) {
|
344
344
|
this.started++;
|
345
345
|
next();
|
@@ -528,7 +528,7 @@ function defaultOnOpen(response) {
|
|
528
528
|
}
|
529
529
|
}
|
530
530
|
|
531
|
-
const VERSION = "0.
|
531
|
+
const VERSION = "0.29.3";
|
532
532
|
|
533
533
|
class ErrorWithCause extends Error {
|
534
534
|
constructor(message, options) {
|
@@ -571,6 +571,67 @@ function getMessage(data) {
|
|
571
571
|
}
|
572
572
|
}
|
573
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\/db\/([^:]+):?(.*)?/),
|
625
|
+
staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev\/db\/([^:]+):?(.*)?/),
|
626
|
+
dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev\/db\/([^:]+):?(.*)?/),
|
627
|
+
local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:([^:]+):?(.*)?/)
|
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], database: match[3], branch: match[4], host };
|
633
|
+
}
|
634
|
+
|
574
635
|
const pool = new ApiRequestPool();
|
575
636
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
576
637
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
@@ -586,6 +647,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
586
647
|
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
587
648
|
};
|
588
649
|
function buildBaseUrl({
|
650
|
+
method,
|
589
651
|
endpoint,
|
590
652
|
path,
|
591
653
|
workspacesApiUrl,
|
@@ -593,7 +655,24 @@ function buildBaseUrl({
|
|
593
655
|
pathParams = {}
|
594
656
|
}) {
|
595
657
|
if (endpoint === "dataPlane") {
|
596
|
-
|
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
|
+
}
|
597
676
|
const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
|
598
677
|
return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
|
599
678
|
}
|
@@ -642,9 +721,9 @@ async function fetch$1({
|
|
642
721
|
return await trace(
|
643
722
|
`${method.toUpperCase()} ${path}`,
|
644
723
|
async ({ setAttributes }) => {
|
645
|
-
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
724
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
646
725
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
647
|
-
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
726
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\.[^.]+\./, "http://") : fullUrl;
|
648
727
|
setAttributes({
|
649
728
|
[TraceAttributes.HTTP_URL]: url,
|
650
729
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
@@ -725,7 +804,7 @@ function fetchSSERequest({
|
|
725
804
|
clientName,
|
726
805
|
xataAgentExtra
|
727
806
|
}) {
|
728
|
-
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
807
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
729
808
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
730
809
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
731
810
|
void fetchEventSource(url, {
|
@@ -768,19 +847,35 @@ function parseUrl(url) {
|
|
768
847
|
|
769
848
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
770
849
|
|
771
|
-
const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/
|
772
|
-
const
|
773
|
-
url: "/db/{dbBranchName}/
|
774
|
-
method: "
|
850
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/apply", method: "post", ...variables, signal });
|
851
|
+
const adaptTable = (variables, signal) => dataPlaneFetch({
|
852
|
+
url: "/db/{dbBranchName}/migrations/adapt/{tableName}",
|
853
|
+
method: "post",
|
854
|
+
...variables,
|
855
|
+
signal
|
856
|
+
});
|
857
|
+
const adaptAllTables = (variables, signal) => dataPlaneFetch({
|
858
|
+
url: "/db/{dbBranchName}/migrations/adapt",
|
859
|
+
method: "post",
|
775
860
|
...variables,
|
776
861
|
signal
|
777
862
|
});
|
863
|
+
const getBranchMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/status", method: "get", ...variables, signal });
|
864
|
+
const getMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/jobs/{jobId}", method: "get", ...variables, signal });
|
865
|
+
const getMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/history", method: "get", ...variables, signal });
|
778
866
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
779
867
|
url: "/dbs/{dbName}",
|
780
868
|
method: "get",
|
781
869
|
...variables,
|
782
870
|
signal
|
783
871
|
});
|
872
|
+
const getDatabaseSettings = (variables, signal) => dataPlaneFetch({
|
873
|
+
url: "/dbs/{dbName}/settings",
|
874
|
+
method: "get",
|
875
|
+
...variables,
|
876
|
+
signal
|
877
|
+
});
|
878
|
+
const updateDatabaseSettings = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/settings", method: "patch", ...variables, signal });
|
784
879
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
785
880
|
url: "/db/{dbBranchName}",
|
786
881
|
method: "get",
|
@@ -981,6 +1076,12 @@ const fileAccess = (variables, signal) => dataPlaneFetch({
|
|
981
1076
|
...variables,
|
982
1077
|
signal
|
983
1078
|
});
|
1079
|
+
const fileUpload = (variables, signal) => dataPlaneFetch({
|
1080
|
+
url: "/file/{fileId}",
|
1081
|
+
method: "put",
|
1082
|
+
...variables,
|
1083
|
+
signal
|
1084
|
+
});
|
984
1085
|
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
985
1086
|
url: "/db/{dbBranchName}/sql",
|
986
1087
|
method: "post",
|
@@ -988,9 +1089,26 @@ const sqlQuery = (variables, signal) => dataPlaneFetch({
|
|
988
1089
|
signal
|
989
1090
|
});
|
990
1091
|
const operationsByTag$2 = {
|
991
|
-
|
1092
|
+
migrations: {
|
992
1093
|
applyMigration,
|
993
|
-
|
1094
|
+
adaptTable,
|
1095
|
+
adaptAllTables,
|
1096
|
+
getBranchMigrationJobStatus,
|
1097
|
+
getMigrationJobStatus,
|
1098
|
+
getMigrationHistory,
|
1099
|
+
getSchema,
|
1100
|
+
getBranchMigrationHistory,
|
1101
|
+
getBranchMigrationPlan,
|
1102
|
+
executeBranchMigrationPlan,
|
1103
|
+
getBranchSchemaHistory,
|
1104
|
+
compareBranchWithUserSchema,
|
1105
|
+
compareBranchSchemas,
|
1106
|
+
updateBranchSchema,
|
1107
|
+
previewBranchSchemaEdit,
|
1108
|
+
applyBranchSchemaEdit,
|
1109
|
+
pushBranchMigrations
|
1110
|
+
},
|
1111
|
+
branch: {
|
994
1112
|
getBranchList,
|
995
1113
|
getBranchDetails,
|
996
1114
|
createBranch,
|
@@ -1004,19 +1122,7 @@ const operationsByTag$2 = {
|
|
1004
1122
|
removeGitBranchesEntry,
|
1005
1123
|
resolveBranch
|
1006
1124
|
},
|
1007
|
-
|
1008
|
-
getSchema,
|
1009
|
-
getBranchMigrationHistory,
|
1010
|
-
getBranchMigrationPlan,
|
1011
|
-
executeBranchMigrationPlan,
|
1012
|
-
getBranchSchemaHistory,
|
1013
|
-
compareBranchWithUserSchema,
|
1014
|
-
compareBranchSchemas,
|
1015
|
-
updateBranchSchema,
|
1016
|
-
previewBranchSchemaEdit,
|
1017
|
-
applyBranchSchemaEdit,
|
1018
|
-
pushBranchMigrations
|
1019
|
-
},
|
1125
|
+
database: { getDatabaseSettings, updateDatabaseSettings },
|
1020
1126
|
migrationRequests: {
|
1021
1127
|
queryMigrationRequests,
|
1022
1128
|
createMigrationRequest,
|
@@ -1049,7 +1155,7 @@ const operationsByTag$2 = {
|
|
1049
1155
|
deleteRecord,
|
1050
1156
|
bulkInsertTableRecords
|
1051
1157
|
},
|
1052
|
-
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1158
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
|
1053
1159
|
searchAndFilter: {
|
1054
1160
|
queryTable,
|
1055
1161
|
searchBranch,
|
@@ -1158,6 +1264,8 @@ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
|
|
1158
1264
|
...variables,
|
1159
1265
|
signal
|
1160
1266
|
});
|
1267
|
+
const getWorkspaceSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/settings", method: "get", ...variables, signal });
|
1268
|
+
const updateWorkspaceSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/settings", method: "patch", ...variables, signal });
|
1161
1269
|
const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
|
1162
1270
|
const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
|
1163
1271
|
const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
|
@@ -1171,12 +1279,7 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
|
|
1171
1279
|
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
1172
1280
|
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
1173
1281
|
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1174
|
-
const listClusters = (variables, signal) => controlPlaneFetch({
|
1175
|
-
url: "/workspaces/{workspaceId}/clusters",
|
1176
|
-
method: "get",
|
1177
|
-
...variables,
|
1178
|
-
signal
|
1179
|
-
});
|
1282
|
+
const listClusters = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "get", ...variables, signal });
|
1180
1283
|
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
1181
1284
|
const getCluster = (variables, signal) => controlPlaneFetch({
|
1182
1285
|
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
@@ -1228,6 +1331,8 @@ const operationsByTag$1 = {
|
|
1228
1331
|
getWorkspace,
|
1229
1332
|
updateWorkspace,
|
1230
1333
|
deleteWorkspace,
|
1334
|
+
getWorkspaceSettings,
|
1335
|
+
updateWorkspaceSettings,
|
1231
1336
|
getWorkspaceMembersList,
|
1232
1337
|
updateWorkspaceMemberRole,
|
1233
1338
|
removeWorkspaceMember
|
@@ -1256,66 +1361,11 @@ const operationsByTag$1 = {
|
|
1256
1361
|
|
1257
1362
|
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
1258
1363
|
|
1259
|
-
function getHostUrl(provider, type) {
|
1260
|
-
if (isHostProviderAlias(provider)) {
|
1261
|
-
return providers[provider][type];
|
1262
|
-
} else if (isHostProviderBuilder(provider)) {
|
1263
|
-
return provider[type];
|
1264
|
-
}
|
1265
|
-
throw new Error("Invalid API provider");
|
1266
|
-
}
|
1267
|
-
const providers = {
|
1268
|
-
production: {
|
1269
|
-
main: "https://api.xata.io",
|
1270
|
-
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
1271
|
-
},
|
1272
|
-
staging: {
|
1273
|
-
main: "https://api.staging-xata.dev",
|
1274
|
-
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1275
|
-
},
|
1276
|
-
dev: {
|
1277
|
-
main: "https://api.dev-xata.dev",
|
1278
|
-
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
1279
|
-
}
|
1280
|
-
};
|
1281
|
-
function isHostProviderAlias(alias) {
|
1282
|
-
return isString(alias) && Object.keys(providers).includes(alias);
|
1283
|
-
}
|
1284
|
-
function isHostProviderBuilder(builder) {
|
1285
|
-
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
1286
|
-
}
|
1287
|
-
function parseProviderString(provider = "production") {
|
1288
|
-
if (isHostProviderAlias(provider)) {
|
1289
|
-
return provider;
|
1290
|
-
}
|
1291
|
-
const [main, workspaces] = provider.split(",");
|
1292
|
-
if (!main || !workspaces)
|
1293
|
-
return null;
|
1294
|
-
return { main, workspaces };
|
1295
|
-
}
|
1296
|
-
function buildProviderString(provider) {
|
1297
|
-
if (isHostProviderAlias(provider))
|
1298
|
-
return provider;
|
1299
|
-
return `${provider.main},${provider.workspaces}`;
|
1300
|
-
}
|
1301
|
-
function parseWorkspacesUrlParts(url) {
|
1302
|
-
if (!isString(url))
|
1303
|
-
return null;
|
1304
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1305
|
-
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1306
|
-
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1307
|
-
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1308
|
-
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
1309
|
-
if (!match)
|
1310
|
-
return null;
|
1311
|
-
return { workspace: match[1], region: match[2] };
|
1312
|
-
}
|
1313
|
-
|
1314
1364
|
var __accessCheck$7 = (obj, member, msg) => {
|
1315
1365
|
if (!member.has(obj))
|
1316
1366
|
throw TypeError("Cannot " + msg);
|
1317
1367
|
};
|
1318
|
-
var __privateGet$
|
1368
|
+
var __privateGet$6 = (obj, member, getter) => {
|
1319
1369
|
__accessCheck$7(obj, member, "read from private field");
|
1320
1370
|
return getter ? getter.call(obj) : member.get(obj);
|
1321
1371
|
};
|
@@ -1324,7 +1374,7 @@ var __privateAdd$7 = (obj, member, value) => {
|
|
1324
1374
|
throw TypeError("Cannot add the same private member more than once");
|
1325
1375
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1326
1376
|
};
|
1327
|
-
var __privateSet$
|
1377
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
1328
1378
|
__accessCheck$7(obj, member, "write to private field");
|
1329
1379
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1330
1380
|
return value;
|
@@ -1341,7 +1391,7 @@ class XataApiClient {
|
|
1341
1391
|
if (!apiKey) {
|
1342
1392
|
throw new Error("Could not resolve a valid apiKey");
|
1343
1393
|
}
|
1344
|
-
__privateSet$
|
1394
|
+
__privateSet$5(this, _extraProps, {
|
1345
1395
|
apiUrl: getHostUrl(provider, "main"),
|
1346
1396
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
1347
1397
|
fetch: getFetchImplementation(options.fetch),
|
@@ -1353,64 +1403,64 @@ class XataApiClient {
|
|
1353
1403
|
});
|
1354
1404
|
}
|
1355
1405
|
get user() {
|
1356
|
-
if (!__privateGet$
|
1357
|
-
__privateGet$
|
1358
|
-
return __privateGet$
|
1406
|
+
if (!__privateGet$6(this, _namespaces).user)
|
1407
|
+
__privateGet$6(this, _namespaces).user = new UserApi(__privateGet$6(this, _extraProps));
|
1408
|
+
return __privateGet$6(this, _namespaces).user;
|
1359
1409
|
}
|
1360
1410
|
get authentication() {
|
1361
|
-
if (!__privateGet$
|
1362
|
-
__privateGet$
|
1363
|
-
return __privateGet$
|
1411
|
+
if (!__privateGet$6(this, _namespaces).authentication)
|
1412
|
+
__privateGet$6(this, _namespaces).authentication = new AuthenticationApi(__privateGet$6(this, _extraProps));
|
1413
|
+
return __privateGet$6(this, _namespaces).authentication;
|
1364
1414
|
}
|
1365
1415
|
get workspaces() {
|
1366
|
-
if (!__privateGet$
|
1367
|
-
__privateGet$
|
1368
|
-
return __privateGet$
|
1416
|
+
if (!__privateGet$6(this, _namespaces).workspaces)
|
1417
|
+
__privateGet$6(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$6(this, _extraProps));
|
1418
|
+
return __privateGet$6(this, _namespaces).workspaces;
|
1369
1419
|
}
|
1370
1420
|
get invites() {
|
1371
|
-
if (!__privateGet$
|
1372
|
-
__privateGet$
|
1373
|
-
return __privateGet$
|
1421
|
+
if (!__privateGet$6(this, _namespaces).invites)
|
1422
|
+
__privateGet$6(this, _namespaces).invites = new InvitesApi(__privateGet$6(this, _extraProps));
|
1423
|
+
return __privateGet$6(this, _namespaces).invites;
|
1374
1424
|
}
|
1375
1425
|
get database() {
|
1376
|
-
if (!__privateGet$
|
1377
|
-
__privateGet$
|
1378
|
-
return __privateGet$
|
1426
|
+
if (!__privateGet$6(this, _namespaces).database)
|
1427
|
+
__privateGet$6(this, _namespaces).database = new DatabaseApi(__privateGet$6(this, _extraProps));
|
1428
|
+
return __privateGet$6(this, _namespaces).database;
|
1379
1429
|
}
|
1380
1430
|
get branches() {
|
1381
|
-
if (!__privateGet$
|
1382
|
-
__privateGet$
|
1383
|
-
return __privateGet$
|
1431
|
+
if (!__privateGet$6(this, _namespaces).branches)
|
1432
|
+
__privateGet$6(this, _namespaces).branches = new BranchApi(__privateGet$6(this, _extraProps));
|
1433
|
+
return __privateGet$6(this, _namespaces).branches;
|
1384
1434
|
}
|
1385
1435
|
get migrations() {
|
1386
|
-
if (!__privateGet$
|
1387
|
-
__privateGet$
|
1388
|
-
return __privateGet$
|
1436
|
+
if (!__privateGet$6(this, _namespaces).migrations)
|
1437
|
+
__privateGet$6(this, _namespaces).migrations = new MigrationsApi(__privateGet$6(this, _extraProps));
|
1438
|
+
return __privateGet$6(this, _namespaces).migrations;
|
1389
1439
|
}
|
1390
1440
|
get migrationRequests() {
|
1391
|
-
if (!__privateGet$
|
1392
|
-
__privateGet$
|
1393
|
-
return __privateGet$
|
1441
|
+
if (!__privateGet$6(this, _namespaces).migrationRequests)
|
1442
|
+
__privateGet$6(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$6(this, _extraProps));
|
1443
|
+
return __privateGet$6(this, _namespaces).migrationRequests;
|
1394
1444
|
}
|
1395
1445
|
get tables() {
|
1396
|
-
if (!__privateGet$
|
1397
|
-
__privateGet$
|
1398
|
-
return __privateGet$
|
1446
|
+
if (!__privateGet$6(this, _namespaces).tables)
|
1447
|
+
__privateGet$6(this, _namespaces).tables = new TableApi(__privateGet$6(this, _extraProps));
|
1448
|
+
return __privateGet$6(this, _namespaces).tables;
|
1399
1449
|
}
|
1400
1450
|
get records() {
|
1401
|
-
if (!__privateGet$
|
1402
|
-
__privateGet$
|
1403
|
-
return __privateGet$
|
1451
|
+
if (!__privateGet$6(this, _namespaces).records)
|
1452
|
+
__privateGet$6(this, _namespaces).records = new RecordsApi(__privateGet$6(this, _extraProps));
|
1453
|
+
return __privateGet$6(this, _namespaces).records;
|
1404
1454
|
}
|
1405
1455
|
get files() {
|
1406
|
-
if (!__privateGet$
|
1407
|
-
__privateGet$
|
1408
|
-
return __privateGet$
|
1456
|
+
if (!__privateGet$6(this, _namespaces).files)
|
1457
|
+
__privateGet$6(this, _namespaces).files = new FilesApi(__privateGet$6(this, _extraProps));
|
1458
|
+
return __privateGet$6(this, _namespaces).files;
|
1409
1459
|
}
|
1410
1460
|
get searchAndFilter() {
|
1411
|
-
if (!__privateGet$
|
1412
|
-
__privateGet$
|
1413
|
-
return __privateGet$
|
1461
|
+
if (!__privateGet$6(this, _namespaces).searchAndFilter)
|
1462
|
+
__privateGet$6(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$6(this, _extraProps));
|
1463
|
+
return __privateGet$6(this, _namespaces).searchAndFilter;
|
1414
1464
|
}
|
1415
1465
|
}
|
1416
1466
|
_extraProps = new WeakMap();
|
@@ -1712,6 +1762,30 @@ class BranchApi {
|
|
1712
1762
|
...this.extraProps
|
1713
1763
|
});
|
1714
1764
|
}
|
1765
|
+
pgRollMigrationHistory({
|
1766
|
+
workspace,
|
1767
|
+
region,
|
1768
|
+
database,
|
1769
|
+
branch
|
1770
|
+
}) {
|
1771
|
+
return operationsByTag.migrations.getMigrationHistory({
|
1772
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1773
|
+
...this.extraProps
|
1774
|
+
});
|
1775
|
+
}
|
1776
|
+
applyMigration({
|
1777
|
+
workspace,
|
1778
|
+
region,
|
1779
|
+
database,
|
1780
|
+
branch,
|
1781
|
+
migration
|
1782
|
+
}) {
|
1783
|
+
return operationsByTag.migrations.applyMigration({
|
1784
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1785
|
+
body: migration,
|
1786
|
+
...this.extraProps
|
1787
|
+
});
|
1788
|
+
}
|
1715
1789
|
}
|
1716
1790
|
class TableApi {
|
1717
1791
|
constructor(extraProps) {
|
@@ -2525,6 +2599,17 @@ class MigrationsApi {
|
|
2525
2599
|
...this.extraProps
|
2526
2600
|
});
|
2527
2601
|
}
|
2602
|
+
getSchema({
|
2603
|
+
workspace,
|
2604
|
+
region,
|
2605
|
+
database,
|
2606
|
+
branch
|
2607
|
+
}) {
|
2608
|
+
return operationsByTag.migrations.getSchema({
|
2609
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2610
|
+
...this.extraProps
|
2611
|
+
});
|
2612
|
+
}
|
2528
2613
|
}
|
2529
2614
|
class DatabaseApi {
|
2530
2615
|
constructor(extraProps) {
|
@@ -2666,16 +2751,18 @@ function transformImage(url, ...transformations) {
|
|
2666
2751
|
class XataFile {
|
2667
2752
|
constructor(file) {
|
2668
2753
|
this.id = file.id;
|
2669
|
-
this.name = file.name
|
2670
|
-
this.mediaType = file.mediaType
|
2754
|
+
this.name = file.name;
|
2755
|
+
this.mediaType = file.mediaType;
|
2671
2756
|
this.base64Content = file.base64Content;
|
2672
|
-
this.enablePublicUrl = file.enablePublicUrl
|
2673
|
-
this.signedUrlTimeout = file.signedUrlTimeout
|
2674
|
-
this.
|
2675
|
-
this.
|
2676
|
-
this.
|
2757
|
+
this.enablePublicUrl = file.enablePublicUrl;
|
2758
|
+
this.signedUrlTimeout = file.signedUrlTimeout;
|
2759
|
+
this.uploadUrlTimeout = file.uploadUrlTimeout;
|
2760
|
+
this.size = file.size;
|
2761
|
+
this.version = file.version;
|
2762
|
+
this.url = file.url;
|
2677
2763
|
this.signedUrl = file.signedUrl;
|
2678
|
-
this.
|
2764
|
+
this.uploadUrl = file.uploadUrl;
|
2765
|
+
this.attributes = file.attributes;
|
2679
2766
|
}
|
2680
2767
|
static fromBuffer(buffer, options = {}) {
|
2681
2768
|
const base64Content = buffer.toString("base64");
|
@@ -2765,7 +2852,7 @@ class XataFile {
|
|
2765
2852
|
const parseInputFileEntry = async (entry) => {
|
2766
2853
|
if (!isDefined(entry))
|
2767
2854
|
return null;
|
2768
|
-
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2855
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
|
2769
2856
|
return compactObject({
|
2770
2857
|
id,
|
2771
2858
|
// Name cannot be an empty string in our API
|
@@ -2773,7 +2860,8 @@ const parseInputFileEntry = async (entry) => {
|
|
2773
2860
|
mediaType,
|
2774
2861
|
base64Content,
|
2775
2862
|
enablePublicUrl,
|
2776
|
-
signedUrlTimeout
|
2863
|
+
signedUrlTimeout,
|
2864
|
+
uploadUrlTimeout
|
2777
2865
|
});
|
2778
2866
|
};
|
2779
2867
|
|
@@ -2827,7 +2915,7 @@ var __accessCheck$6 = (obj, member, msg) => {
|
|
2827
2915
|
if (!member.has(obj))
|
2828
2916
|
throw TypeError("Cannot " + msg);
|
2829
2917
|
};
|
2830
|
-
var __privateGet$
|
2918
|
+
var __privateGet$5 = (obj, member, getter) => {
|
2831
2919
|
__accessCheck$6(obj, member, "read from private field");
|
2832
2920
|
return getter ? getter.call(obj) : member.get(obj);
|
2833
2921
|
};
|
@@ -2836,7 +2924,7 @@ var __privateAdd$6 = (obj, member, value) => {
|
|
2836
2924
|
throw TypeError("Cannot add the same private member more than once");
|
2837
2925
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
2838
2926
|
};
|
2839
|
-
var __privateSet$
|
2927
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
2840
2928
|
__accessCheck$6(obj, member, "write to private field");
|
2841
2929
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
2842
2930
|
return value;
|
@@ -2845,9 +2933,9 @@ var _query, _page;
|
|
2845
2933
|
class Page {
|
2846
2934
|
constructor(query, meta, records = []) {
|
2847
2935
|
__privateAdd$6(this, _query, void 0);
|
2848
|
-
__privateSet$
|
2936
|
+
__privateSet$4(this, _query, query);
|
2849
2937
|
this.meta = meta;
|
2850
|
-
this.records = new
|
2938
|
+
this.records = new PageRecordArray(this, records);
|
2851
2939
|
}
|
2852
2940
|
/**
|
2853
2941
|
* Retrieves the next page of results.
|
@@ -2856,7 +2944,7 @@ class Page {
|
|
2856
2944
|
* @returns The next page or results.
|
2857
2945
|
*/
|
2858
2946
|
async nextPage(size, offset) {
|
2859
|
-
return __privateGet$
|
2947
|
+
return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
2860
2948
|
}
|
2861
2949
|
/**
|
2862
2950
|
* Retrieves the previous page of results.
|
@@ -2865,7 +2953,7 @@ class Page {
|
|
2865
2953
|
* @returns The previous page or results.
|
2866
2954
|
*/
|
2867
2955
|
async previousPage(size, offset) {
|
2868
|
-
return __privateGet$
|
2956
|
+
return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
2869
2957
|
}
|
2870
2958
|
/**
|
2871
2959
|
* Retrieves the start page of results.
|
@@ -2874,7 +2962,7 @@ class Page {
|
|
2874
2962
|
* @returns The start page or results.
|
2875
2963
|
*/
|
2876
2964
|
async startPage(size, offset) {
|
2877
|
-
return __privateGet$
|
2965
|
+
return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
2878
2966
|
}
|
2879
2967
|
/**
|
2880
2968
|
* Retrieves the end page of results.
|
@@ -2883,7 +2971,7 @@ class Page {
|
|
2883
2971
|
* @returns The end page or results.
|
2884
2972
|
*/
|
2885
2973
|
async endPage(size, offset) {
|
2886
|
-
return __privateGet$
|
2974
|
+
return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
2887
2975
|
}
|
2888
2976
|
/**
|
2889
2977
|
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
@@ -2901,11 +2989,38 @@ const PAGINATION_DEFAULT_OFFSET = 0;
|
|
2901
2989
|
function isCursorPaginationOptions(options) {
|
2902
2990
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
2903
2991
|
}
|
2904
|
-
|
2992
|
+
class RecordArray extends Array {
|
2905
2993
|
constructor(...args) {
|
2906
|
-
super(...
|
2994
|
+
super(...RecordArray.parseConstructorParams(...args));
|
2995
|
+
}
|
2996
|
+
static parseConstructorParams(...args) {
|
2997
|
+
if (args.length === 1 && typeof args[0] === "number") {
|
2998
|
+
return new Array(args[0]);
|
2999
|
+
}
|
3000
|
+
if (args.length <= 1 && Array.isArray(args[0] ?? [])) {
|
3001
|
+
const result = args[0] ?? [];
|
3002
|
+
return new Array(...result);
|
3003
|
+
}
|
3004
|
+
return new Array(...args);
|
3005
|
+
}
|
3006
|
+
toArray() {
|
3007
|
+
return new Array(...this);
|
3008
|
+
}
|
3009
|
+
toSerializable() {
|
3010
|
+
return JSON.parse(this.toString());
|
3011
|
+
}
|
3012
|
+
toString() {
|
3013
|
+
return JSON.stringify(this.toArray());
|
3014
|
+
}
|
3015
|
+
map(callbackfn, thisArg) {
|
3016
|
+
return this.toArray().map(callbackfn, thisArg);
|
3017
|
+
}
|
3018
|
+
}
|
3019
|
+
const _PageRecordArray = class _PageRecordArray extends Array {
|
3020
|
+
constructor(...args) {
|
3021
|
+
super(..._PageRecordArray.parseConstructorParams(...args));
|
2907
3022
|
__privateAdd$6(this, _page, void 0);
|
2908
|
-
__privateSet$
|
3023
|
+
__privateSet$4(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
2909
3024
|
}
|
2910
3025
|
static parseConstructorParams(...args) {
|
2911
3026
|
if (args.length === 1 && typeof args[0] === "number") {
|
@@ -2935,8 +3050,8 @@ const _RecordArray = class _RecordArray extends Array {
|
|
2935
3050
|
* @returns A new array of objects
|
2936
3051
|
*/
|
2937
3052
|
async nextPage(size, offset) {
|
2938
|
-
const newPage = await __privateGet$
|
2939
|
-
return new
|
3053
|
+
const newPage = await __privateGet$5(this, _page).nextPage(size, offset);
|
3054
|
+
return new _PageRecordArray(newPage);
|
2940
3055
|
}
|
2941
3056
|
/**
|
2942
3057
|
* Retrieve previous page of records
|
@@ -2944,8 +3059,8 @@ const _RecordArray = class _RecordArray extends Array {
|
|
2944
3059
|
* @returns A new array of objects
|
2945
3060
|
*/
|
2946
3061
|
async previousPage(size, offset) {
|
2947
|
-
const newPage = await __privateGet$
|
2948
|
-
return new
|
3062
|
+
const newPage = await __privateGet$5(this, _page).previousPage(size, offset);
|
3063
|
+
return new _PageRecordArray(newPage);
|
2949
3064
|
}
|
2950
3065
|
/**
|
2951
3066
|
* Retrieve start page of records
|
@@ -2953,8 +3068,8 @@ const _RecordArray = class _RecordArray extends Array {
|
|
2953
3068
|
* @returns A new array of objects
|
2954
3069
|
*/
|
2955
3070
|
async startPage(size, offset) {
|
2956
|
-
const newPage = await __privateGet$
|
2957
|
-
return new
|
3071
|
+
const newPage = await __privateGet$5(this, _page).startPage(size, offset);
|
3072
|
+
return new _PageRecordArray(newPage);
|
2958
3073
|
}
|
2959
3074
|
/**
|
2960
3075
|
* Retrieve end page of records
|
@@ -2962,24 +3077,24 @@ const _RecordArray = class _RecordArray extends Array {
|
|
2962
3077
|
* @returns A new array of objects
|
2963
3078
|
*/
|
2964
3079
|
async endPage(size, offset) {
|
2965
|
-
const newPage = await __privateGet$
|
2966
|
-
return new
|
3080
|
+
const newPage = await __privateGet$5(this, _page).endPage(size, offset);
|
3081
|
+
return new _PageRecordArray(newPage);
|
2967
3082
|
}
|
2968
3083
|
/**
|
2969
3084
|
* @returns Boolean indicating if there is a next page
|
2970
3085
|
*/
|
2971
3086
|
hasNextPage() {
|
2972
|
-
return __privateGet$
|
3087
|
+
return __privateGet$5(this, _page).meta.page.more;
|
2973
3088
|
}
|
2974
3089
|
};
|
2975
3090
|
_page = new WeakMap();
|
2976
|
-
let
|
3091
|
+
let PageRecordArray = _PageRecordArray;
|
2977
3092
|
|
2978
3093
|
var __accessCheck$5 = (obj, member, msg) => {
|
2979
3094
|
if (!member.has(obj))
|
2980
3095
|
throw TypeError("Cannot " + msg);
|
2981
3096
|
};
|
2982
|
-
var __privateGet$
|
3097
|
+
var __privateGet$4 = (obj, member, getter) => {
|
2983
3098
|
__accessCheck$5(obj, member, "read from private field");
|
2984
3099
|
return getter ? getter.call(obj) : member.get(obj);
|
2985
3100
|
};
|
@@ -2988,7 +3103,7 @@ var __privateAdd$5 = (obj, member, value) => {
|
|
2988
3103
|
throw TypeError("Cannot add the same private member more than once");
|
2989
3104
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
2990
3105
|
};
|
2991
|
-
var __privateSet$
|
3106
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
2992
3107
|
__accessCheck$5(obj, member, "write to private field");
|
2993
3108
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
2994
3109
|
return value;
|
@@ -3006,25 +3121,25 @@ const _Query = class _Query {
|
|
3006
3121
|
__privateAdd$5(this, _data, { filter: {} });
|
3007
3122
|
// Implements pagination
|
3008
3123
|
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
3009
|
-
this.records = new
|
3010
|
-
__privateSet$
|
3124
|
+
this.records = new PageRecordArray(this, []);
|
3125
|
+
__privateSet$3(this, _table$1, table);
|
3011
3126
|
if (repository) {
|
3012
|
-
__privateSet$
|
3127
|
+
__privateSet$3(this, _repository, repository);
|
3013
3128
|
} else {
|
3014
|
-
__privateSet$
|
3129
|
+
__privateSet$3(this, _repository, this);
|
3015
3130
|
}
|
3016
3131
|
const parent = cleanParent(data, rawParent);
|
3017
|
-
__privateGet$
|
3018
|
-
__privateGet$
|
3019
|
-
__privateGet$
|
3020
|
-
__privateGet$
|
3021
|
-
__privateGet$
|
3022
|
-
__privateGet$
|
3023
|
-
__privateGet$
|
3024
|
-
__privateGet$
|
3025
|
-
__privateGet$
|
3026
|
-
__privateGet$
|
3027
|
-
__privateGet$
|
3132
|
+
__privateGet$4(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
3133
|
+
__privateGet$4(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
|
3134
|
+
__privateGet$4(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
|
3135
|
+
__privateGet$4(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
|
3136
|
+
__privateGet$4(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
3137
|
+
__privateGet$4(this, _data).sort = data.sort ?? parent?.sort;
|
3138
|
+
__privateGet$4(this, _data).columns = data.columns ?? parent?.columns;
|
3139
|
+
__privateGet$4(this, _data).consistency = data.consistency ?? parent?.consistency;
|
3140
|
+
__privateGet$4(this, _data).pagination = data.pagination ?? parent?.pagination;
|
3141
|
+
__privateGet$4(this, _data).cache = data.cache ?? parent?.cache;
|
3142
|
+
__privateGet$4(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
3028
3143
|
this.any = this.any.bind(this);
|
3029
3144
|
this.all = this.all.bind(this);
|
3030
3145
|
this.not = this.not.bind(this);
|
@@ -3035,10 +3150,10 @@ const _Query = class _Query {
|
|
3035
3150
|
Object.defineProperty(this, "repository", { enumerable: false });
|
3036
3151
|
}
|
3037
3152
|
getQueryOptions() {
|
3038
|
-
return __privateGet$
|
3153
|
+
return __privateGet$4(this, _data);
|
3039
3154
|
}
|
3040
3155
|
key() {
|
3041
|
-
const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$
|
3156
|
+
const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$4(this, _data);
|
3042
3157
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
3043
3158
|
return toBase64(key);
|
3044
3159
|
}
|
@@ -3049,7 +3164,7 @@ const _Query = class _Query {
|
|
3049
3164
|
*/
|
3050
3165
|
any(...queries) {
|
3051
3166
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
3052
|
-
return new _Query(__privateGet$
|
3167
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $any } }, __privateGet$4(this, _data));
|
3053
3168
|
}
|
3054
3169
|
/**
|
3055
3170
|
* Builds a new query object representing a logical AND between the given subqueries.
|
@@ -3058,7 +3173,7 @@ const _Query = class _Query {
|
|
3058
3173
|
*/
|
3059
3174
|
all(...queries) {
|
3060
3175
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
3061
|
-
return new _Query(__privateGet$
|
3176
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
|
3062
3177
|
}
|
3063
3178
|
/**
|
3064
3179
|
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
@@ -3067,7 +3182,7 @@ const _Query = class _Query {
|
|
3067
3182
|
*/
|
3068
3183
|
not(...queries) {
|
3069
3184
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
3070
|
-
return new _Query(__privateGet$
|
3185
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $not } }, __privateGet$4(this, _data));
|
3071
3186
|
}
|
3072
3187
|
/**
|
3073
3188
|
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
@@ -3076,25 +3191,25 @@ const _Query = class _Query {
|
|
3076
3191
|
*/
|
3077
3192
|
none(...queries) {
|
3078
3193
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
3079
|
-
return new _Query(__privateGet$
|
3194
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $none } }, __privateGet$4(this, _data));
|
3080
3195
|
}
|
3081
3196
|
filter(a, b) {
|
3082
3197
|
if (arguments.length === 1) {
|
3083
3198
|
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
3084
3199
|
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
3085
3200
|
}));
|
3086
|
-
const $all = compact([__privateGet$
|
3087
|
-
return new _Query(__privateGet$
|
3201
|
+
const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat(constraints));
|
3202
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
|
3088
3203
|
} else {
|
3089
3204
|
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
3090
|
-
const $all = compact([__privateGet$
|
3091
|
-
return new _Query(__privateGet$
|
3205
|
+
const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat(constraints));
|
3206
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
|
3092
3207
|
}
|
3093
3208
|
}
|
3094
3209
|
sort(column, direction = "asc") {
|
3095
|
-
const originalSort = [__privateGet$
|
3210
|
+
const originalSort = [__privateGet$4(this, _data).sort ?? []].flat();
|
3096
3211
|
const sort = [...originalSort, { column, direction }];
|
3097
|
-
return new _Query(__privateGet$
|
3212
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { sort }, __privateGet$4(this, _data));
|
3098
3213
|
}
|
3099
3214
|
/**
|
3100
3215
|
* Builds a new query specifying the set of columns to be returned in the query response.
|
@@ -3103,15 +3218,15 @@ const _Query = class _Query {
|
|
3103
3218
|
*/
|
3104
3219
|
select(columns) {
|
3105
3220
|
return new _Query(
|
3106
|
-
__privateGet$
|
3107
|
-
__privateGet$
|
3221
|
+
__privateGet$4(this, _repository),
|
3222
|
+
__privateGet$4(this, _table$1),
|
3108
3223
|
{ columns },
|
3109
|
-
__privateGet$
|
3224
|
+
__privateGet$4(this, _data)
|
3110
3225
|
);
|
3111
3226
|
}
|
3112
3227
|
getPaginated(options = {}) {
|
3113
|
-
const query = new _Query(__privateGet$
|
3114
|
-
return __privateGet$
|
3228
|
+
const query = new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), options, __privateGet$4(this, _data));
|
3229
|
+
return __privateGet$4(this, _repository).query(query);
|
3115
3230
|
}
|
3116
3231
|
/**
|
3117
3232
|
* Get results in an iterator
|
@@ -3148,7 +3263,7 @@ const _Query = class _Query {
|
|
3148
3263
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
3149
3264
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
3150
3265
|
}
|
3151
|
-
const array = new
|
3266
|
+
const array = new PageRecordArray(page, results.slice(0, size));
|
3152
3267
|
return array;
|
3153
3268
|
}
|
3154
3269
|
async getAll(options = {}) {
|
@@ -3157,7 +3272,7 @@ const _Query = class _Query {
|
|
3157
3272
|
for await (const page of this.getIterator({ ...rest, batchSize })) {
|
3158
3273
|
results.push(...page);
|
3159
3274
|
}
|
3160
|
-
return results;
|
3275
|
+
return new RecordArray(results);
|
3161
3276
|
}
|
3162
3277
|
async getFirst(options = {}) {
|
3163
3278
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
@@ -3172,12 +3287,12 @@ const _Query = class _Query {
|
|
3172
3287
|
async summarize(params = {}) {
|
3173
3288
|
const { summaries, summariesFilter, ...options } = params;
|
3174
3289
|
const query = new _Query(
|
3175
|
-
__privateGet$
|
3176
|
-
__privateGet$
|
3290
|
+
__privateGet$4(this, _repository),
|
3291
|
+
__privateGet$4(this, _table$1),
|
3177
3292
|
options,
|
3178
|
-
__privateGet$
|
3293
|
+
__privateGet$4(this, _data)
|
3179
3294
|
);
|
3180
|
-
return __privateGet$
|
3295
|
+
return __privateGet$4(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
3181
3296
|
}
|
3182
3297
|
/**
|
3183
3298
|
* Builds a new query object adding a cache TTL in milliseconds.
|
@@ -3185,7 +3300,7 @@ const _Query = class _Query {
|
|
3185
3300
|
* @returns A new Query object.
|
3186
3301
|
*/
|
3187
3302
|
cache(ttl) {
|
3188
|
-
return new _Query(__privateGet$
|
3303
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { cache: ttl }, __privateGet$4(this, _data));
|
3189
3304
|
}
|
3190
3305
|
/**
|
3191
3306
|
* Retrieve next page of records
|
@@ -3231,7 +3346,7 @@ _repository = new WeakMap();
|
|
3231
3346
|
_data = new WeakMap();
|
3232
3347
|
_cleanFilterConstraint = new WeakSet();
|
3233
3348
|
cleanFilterConstraint_fn = function(column, value) {
|
3234
|
-
const columnType = __privateGet$
|
3349
|
+
const columnType = __privateGet$4(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
3235
3350
|
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
3236
3351
|
return { $includes: value };
|
3237
3352
|
}
|
@@ -3257,7 +3372,6 @@ const RecordColumnTypes = [
|
|
3257
3372
|
"email",
|
3258
3373
|
"multiple",
|
3259
3374
|
"link",
|
3260
|
-
"object",
|
3261
3375
|
"datetime",
|
3262
3376
|
"vector",
|
3263
3377
|
"file[]",
|
@@ -3322,7 +3436,7 @@ var __accessCheck$4 = (obj, member, msg) => {
|
|
3322
3436
|
if (!member.has(obj))
|
3323
3437
|
throw TypeError("Cannot " + msg);
|
3324
3438
|
};
|
3325
|
-
var __privateGet$
|
3439
|
+
var __privateGet$3 = (obj, member, getter) => {
|
3326
3440
|
__accessCheck$4(obj, member, "read from private field");
|
3327
3441
|
return getter ? getter.call(obj) : member.get(obj);
|
3328
3442
|
};
|
@@ -3331,7 +3445,7 @@ var __privateAdd$4 = (obj, member, value) => {
|
|
3331
3445
|
throw TypeError("Cannot add the same private member more than once");
|
3332
3446
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
3333
3447
|
};
|
3334
|
-
var __privateSet$
|
3448
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
3335
3449
|
__accessCheck$4(obj, member, "write to private field");
|
3336
3450
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
3337
3451
|
return value;
|
@@ -3340,7 +3454,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
3340
3454
|
__accessCheck$4(obj, member, "access private method");
|
3341
3455
|
return method;
|
3342
3456
|
};
|
3343
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables
|
3457
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables, getSchemaTables_fn, _transformObjectToApi, transformObjectToApi_fn;
|
3344
3458
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
3345
3459
|
class Repository extends Query {
|
3346
3460
|
}
|
@@ -3361,31 +3475,31 @@ class RestRepository extends Query {
|
|
3361
3475
|
__privateAdd$4(this, _deleteRecords);
|
3362
3476
|
__privateAdd$4(this, _setCacheQuery);
|
3363
3477
|
__privateAdd$4(this, _getCacheQuery);
|
3364
|
-
__privateAdd$4(this, _getSchemaTables
|
3478
|
+
__privateAdd$4(this, _getSchemaTables);
|
3365
3479
|
__privateAdd$4(this, _transformObjectToApi);
|
3366
3480
|
__privateAdd$4(this, _table, void 0);
|
3367
3481
|
__privateAdd$4(this, _getFetchProps, void 0);
|
3368
3482
|
__privateAdd$4(this, _db, void 0);
|
3369
3483
|
__privateAdd$4(this, _cache, void 0);
|
3370
|
-
__privateAdd$4(this, _schemaTables
|
3484
|
+
__privateAdd$4(this, _schemaTables, void 0);
|
3371
3485
|
__privateAdd$4(this, _trace, void 0);
|
3372
|
-
__privateSet$
|
3373
|
-
__privateSet$
|
3374
|
-
__privateSet$
|
3375
|
-
__privateSet$
|
3376
|
-
__privateSet$
|
3486
|
+
__privateSet$2(this, _table, options.table);
|
3487
|
+
__privateSet$2(this, _db, options.db);
|
3488
|
+
__privateSet$2(this, _cache, options.pluginOptions.cache);
|
3489
|
+
__privateSet$2(this, _schemaTables, options.schemaTables);
|
3490
|
+
__privateSet$2(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
3377
3491
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
3378
|
-
__privateSet$
|
3492
|
+
__privateSet$2(this, _trace, async (name, fn, options2 = {}) => {
|
3379
3493
|
return trace(name, fn, {
|
3380
3494
|
...options2,
|
3381
|
-
[TraceAttributes.TABLE]: __privateGet$
|
3495
|
+
[TraceAttributes.TABLE]: __privateGet$3(this, _table),
|
3382
3496
|
[TraceAttributes.KIND]: "sdk-operation",
|
3383
3497
|
[TraceAttributes.VERSION]: VERSION
|
3384
3498
|
});
|
3385
3499
|
});
|
3386
3500
|
}
|
3387
3501
|
async create(a, b, c, d) {
|
3388
|
-
return __privateGet$
|
3502
|
+
return __privateGet$3(this, _trace).call(this, "create", async () => {
|
3389
3503
|
const ifVersion = parseIfVersion(b, c, d);
|
3390
3504
|
if (Array.isArray(a)) {
|
3391
3505
|
if (a.length === 0)
|
@@ -3415,7 +3529,7 @@ class RestRepository extends Query {
|
|
3415
3529
|
});
|
3416
3530
|
}
|
3417
3531
|
async read(a, b) {
|
3418
|
-
return __privateGet$
|
3532
|
+
return __privateGet$3(this, _trace).call(this, "read", async () => {
|
3419
3533
|
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3420
3534
|
if (Array.isArray(a)) {
|
3421
3535
|
if (a.length === 0)
|
@@ -3436,17 +3550,17 @@ class RestRepository extends Query {
|
|
3436
3550
|
workspace: "{workspaceId}",
|
3437
3551
|
dbBranchName: "{dbBranch}",
|
3438
3552
|
region: "{region}",
|
3439
|
-
tableName: __privateGet$
|
3553
|
+
tableName: __privateGet$3(this, _table),
|
3440
3554
|
recordId: id
|
3441
3555
|
},
|
3442
3556
|
queryParams: { columns },
|
3443
|
-
...__privateGet$
|
3557
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3444
3558
|
});
|
3445
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3559
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3446
3560
|
return initObject(
|
3447
|
-
__privateGet$
|
3561
|
+
__privateGet$3(this, _db),
|
3448
3562
|
schemaTables,
|
3449
|
-
__privateGet$
|
3563
|
+
__privateGet$3(this, _table),
|
3450
3564
|
response,
|
3451
3565
|
columns
|
3452
3566
|
);
|
@@ -3461,7 +3575,7 @@ class RestRepository extends Query {
|
|
3461
3575
|
});
|
3462
3576
|
}
|
3463
3577
|
async readOrThrow(a, b) {
|
3464
|
-
return __privateGet$
|
3578
|
+
return __privateGet$3(this, _trace).call(this, "readOrThrow", async () => {
|
3465
3579
|
const result = await this.read(a, b);
|
3466
3580
|
if (Array.isArray(result)) {
|
3467
3581
|
const missingIds = compact(
|
@@ -3480,7 +3594,7 @@ class RestRepository extends Query {
|
|
3480
3594
|
});
|
3481
3595
|
}
|
3482
3596
|
async update(a, b, c, d) {
|
3483
|
-
return __privateGet$
|
3597
|
+
return __privateGet$3(this, _trace).call(this, "update", async () => {
|
3484
3598
|
const ifVersion = parseIfVersion(b, c, d);
|
3485
3599
|
if (Array.isArray(a)) {
|
3486
3600
|
if (a.length === 0)
|
@@ -3513,7 +3627,7 @@ class RestRepository extends Query {
|
|
3513
3627
|
});
|
3514
3628
|
}
|
3515
3629
|
async updateOrThrow(a, b, c, d) {
|
3516
|
-
return __privateGet$
|
3630
|
+
return __privateGet$3(this, _trace).call(this, "updateOrThrow", async () => {
|
3517
3631
|
const result = await this.update(a, b, c, d);
|
3518
3632
|
if (Array.isArray(result)) {
|
3519
3633
|
const missingIds = compact(
|
@@ -3532,7 +3646,7 @@ class RestRepository extends Query {
|
|
3532
3646
|
});
|
3533
3647
|
}
|
3534
3648
|
async createOrUpdate(a, b, c, d) {
|
3535
|
-
return __privateGet$
|
3649
|
+
return __privateGet$3(this, _trace).call(this, "createOrUpdate", async () => {
|
3536
3650
|
const ifVersion = parseIfVersion(b, c, d);
|
3537
3651
|
if (Array.isArray(a)) {
|
3538
3652
|
if (a.length === 0)
|
@@ -3567,7 +3681,7 @@ class RestRepository extends Query {
|
|
3567
3681
|
});
|
3568
3682
|
}
|
3569
3683
|
async createOrReplace(a, b, c, d) {
|
3570
|
-
return __privateGet$
|
3684
|
+
return __privateGet$3(this, _trace).call(this, "createOrReplace", async () => {
|
3571
3685
|
const ifVersion = parseIfVersion(b, c, d);
|
3572
3686
|
if (Array.isArray(a)) {
|
3573
3687
|
if (a.length === 0)
|
@@ -3599,7 +3713,7 @@ class RestRepository extends Query {
|
|
3599
3713
|
});
|
3600
3714
|
}
|
3601
3715
|
async delete(a, b) {
|
3602
|
-
return __privateGet$
|
3716
|
+
return __privateGet$3(this, _trace).call(this, "delete", async () => {
|
3603
3717
|
if (Array.isArray(a)) {
|
3604
3718
|
if (a.length === 0)
|
3605
3719
|
return [];
|
@@ -3625,7 +3739,7 @@ class RestRepository extends Query {
|
|
3625
3739
|
});
|
3626
3740
|
}
|
3627
3741
|
async deleteOrThrow(a, b) {
|
3628
|
-
return __privateGet$
|
3742
|
+
return __privateGet$3(this, _trace).call(this, "deleteOrThrow", async () => {
|
3629
3743
|
const result = await this.delete(a, b);
|
3630
3744
|
if (Array.isArray(result)) {
|
3631
3745
|
const missingIds = compact(
|
@@ -3643,13 +3757,13 @@ class RestRepository extends Query {
|
|
3643
3757
|
});
|
3644
3758
|
}
|
3645
3759
|
async search(query, options = {}) {
|
3646
|
-
return __privateGet$
|
3760
|
+
return __privateGet$3(this, _trace).call(this, "search", async () => {
|
3647
3761
|
const { records, totalCount } = await searchTable({
|
3648
3762
|
pathParams: {
|
3649
3763
|
workspace: "{workspaceId}",
|
3650
3764
|
dbBranchName: "{dbBranch}",
|
3651
3765
|
region: "{region}",
|
3652
|
-
tableName: __privateGet$
|
3766
|
+
tableName: __privateGet$3(this, _table)
|
3653
3767
|
},
|
3654
3768
|
body: {
|
3655
3769
|
query,
|
@@ -3661,23 +3775,23 @@ class RestRepository extends Query {
|
|
3661
3775
|
page: options.page,
|
3662
3776
|
target: options.target
|
3663
3777
|
},
|
3664
|
-
...__privateGet$
|
3778
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3665
3779
|
});
|
3666
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3780
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3667
3781
|
return {
|
3668
|
-
records: records.map((item) => initObject(__privateGet$
|
3782
|
+
records: records.map((item) => initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), item, ["*"])),
|
3669
3783
|
totalCount
|
3670
3784
|
};
|
3671
3785
|
});
|
3672
3786
|
}
|
3673
3787
|
async vectorSearch(column, query, options) {
|
3674
|
-
return __privateGet$
|
3788
|
+
return __privateGet$3(this, _trace).call(this, "vectorSearch", async () => {
|
3675
3789
|
const { records, totalCount } = await vectorSearchTable({
|
3676
3790
|
pathParams: {
|
3677
3791
|
workspace: "{workspaceId}",
|
3678
3792
|
dbBranchName: "{dbBranch}",
|
3679
3793
|
region: "{region}",
|
3680
|
-
tableName: __privateGet$
|
3794
|
+
tableName: __privateGet$3(this, _table)
|
3681
3795
|
},
|
3682
3796
|
body: {
|
3683
3797
|
column,
|
@@ -3686,32 +3800,32 @@ class RestRepository extends Query {
|
|
3686
3800
|
size: options?.size,
|
3687
3801
|
filter: options?.filter
|
3688
3802
|
},
|
3689
|
-
...__privateGet$
|
3803
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3690
3804
|
});
|
3691
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3805
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3692
3806
|
return {
|
3693
|
-
records: records.map((item) => initObject(__privateGet$
|
3807
|
+
records: records.map((item) => initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), item, ["*"])),
|
3694
3808
|
totalCount
|
3695
3809
|
};
|
3696
3810
|
});
|
3697
3811
|
}
|
3698
3812
|
async aggregate(aggs, filter) {
|
3699
|
-
return __privateGet$
|
3813
|
+
return __privateGet$3(this, _trace).call(this, "aggregate", async () => {
|
3700
3814
|
const result = await aggregateTable({
|
3701
3815
|
pathParams: {
|
3702
3816
|
workspace: "{workspaceId}",
|
3703
3817
|
dbBranchName: "{dbBranch}",
|
3704
3818
|
region: "{region}",
|
3705
|
-
tableName: __privateGet$
|
3819
|
+
tableName: __privateGet$3(this, _table)
|
3706
3820
|
},
|
3707
3821
|
body: { aggs, filter },
|
3708
|
-
...__privateGet$
|
3822
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3709
3823
|
});
|
3710
3824
|
return result;
|
3711
3825
|
});
|
3712
3826
|
}
|
3713
3827
|
async query(query) {
|
3714
|
-
return __privateGet$
|
3828
|
+
return __privateGet$3(this, _trace).call(this, "query", async () => {
|
3715
3829
|
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
3716
3830
|
if (cacheQuery)
|
3717
3831
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
@@ -3721,7 +3835,7 @@ class RestRepository extends Query {
|
|
3721
3835
|
workspace: "{workspaceId}",
|
3722
3836
|
dbBranchName: "{dbBranch}",
|
3723
3837
|
region: "{region}",
|
3724
|
-
tableName: __privateGet$
|
3838
|
+
tableName: __privateGet$3(this, _table)
|
3725
3839
|
},
|
3726
3840
|
body: {
|
3727
3841
|
filter: cleanFilter(data.filter),
|
@@ -3731,14 +3845,14 @@ class RestRepository extends Query {
|
|
3731
3845
|
consistency: data.consistency
|
3732
3846
|
},
|
3733
3847
|
fetchOptions: data.fetchOptions,
|
3734
|
-
...__privateGet$
|
3848
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3735
3849
|
});
|
3736
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3850
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3737
3851
|
const records = objects.map(
|
3738
3852
|
(record) => initObject(
|
3739
|
-
__privateGet$
|
3853
|
+
__privateGet$3(this, _db),
|
3740
3854
|
schemaTables,
|
3741
|
-
__privateGet$
|
3855
|
+
__privateGet$3(this, _table),
|
3742
3856
|
record,
|
3743
3857
|
data.columns ?? ["*"]
|
3744
3858
|
)
|
@@ -3748,14 +3862,14 @@ class RestRepository extends Query {
|
|
3748
3862
|
});
|
3749
3863
|
}
|
3750
3864
|
async summarizeTable(query, summaries, summariesFilter) {
|
3751
|
-
return __privateGet$
|
3865
|
+
return __privateGet$3(this, _trace).call(this, "summarize", async () => {
|
3752
3866
|
const data = query.getQueryOptions();
|
3753
3867
|
const result = await summarizeTable({
|
3754
3868
|
pathParams: {
|
3755
3869
|
workspace: "{workspaceId}",
|
3756
3870
|
dbBranchName: "{dbBranch}",
|
3757
3871
|
region: "{region}",
|
3758
|
-
tableName: __privateGet$
|
3872
|
+
tableName: __privateGet$3(this, _table)
|
3759
3873
|
},
|
3760
3874
|
body: {
|
3761
3875
|
filter: cleanFilter(data.filter),
|
@@ -3766,13 +3880,13 @@ class RestRepository extends Query {
|
|
3766
3880
|
summaries,
|
3767
3881
|
summariesFilter
|
3768
3882
|
},
|
3769
|
-
...__privateGet$
|
3883
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3770
3884
|
});
|
3771
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3885
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3772
3886
|
return {
|
3773
3887
|
...result,
|
3774
3888
|
summaries: result.summaries.map(
|
3775
|
-
(summary) => initObject(__privateGet$
|
3889
|
+
(summary) => initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), summary, data.columns ?? [])
|
3776
3890
|
)
|
3777
3891
|
};
|
3778
3892
|
});
|
@@ -3784,7 +3898,7 @@ class RestRepository extends Query {
|
|
3784
3898
|
workspace: "{workspaceId}",
|
3785
3899
|
dbBranchName: "{dbBranch}",
|
3786
3900
|
region: "{region}",
|
3787
|
-
tableName: __privateGet$
|
3901
|
+
tableName: __privateGet$3(this, _table),
|
3788
3902
|
sessionId: options?.sessionId
|
3789
3903
|
},
|
3790
3904
|
body: {
|
@@ -3794,7 +3908,7 @@ class RestRepository extends Query {
|
|
3794
3908
|
search: options?.searchType === "keyword" ? options?.search : void 0,
|
3795
3909
|
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
3796
3910
|
},
|
3797
|
-
...__privateGet$
|
3911
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3798
3912
|
};
|
3799
3913
|
if (options?.onMessage) {
|
3800
3914
|
fetchSSERequest({
|
@@ -3815,7 +3929,7 @@ _table = new WeakMap();
|
|
3815
3929
|
_getFetchProps = new WeakMap();
|
3816
3930
|
_db = new WeakMap();
|
3817
3931
|
_cache = new WeakMap();
|
3818
|
-
_schemaTables
|
3932
|
+
_schemaTables = new WeakMap();
|
3819
3933
|
_trace = new WeakMap();
|
3820
3934
|
_insertRecordWithoutId = new WeakSet();
|
3821
3935
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
@@ -3825,14 +3939,14 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
3825
3939
|
workspace: "{workspaceId}",
|
3826
3940
|
dbBranchName: "{dbBranch}",
|
3827
3941
|
region: "{region}",
|
3828
|
-
tableName: __privateGet$
|
3942
|
+
tableName: __privateGet$3(this, _table)
|
3829
3943
|
},
|
3830
3944
|
queryParams: { columns },
|
3831
3945
|
body: record,
|
3832
|
-
...__privateGet$
|
3946
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3833
3947
|
});
|
3834
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3835
|
-
return initObject(__privateGet$
|
3948
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3949
|
+
return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
|
3836
3950
|
};
|
3837
3951
|
_insertRecordWithId = new WeakSet();
|
3838
3952
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
@@ -3844,21 +3958,21 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
3844
3958
|
workspace: "{workspaceId}",
|
3845
3959
|
dbBranchName: "{dbBranch}",
|
3846
3960
|
region: "{region}",
|
3847
|
-
tableName: __privateGet$
|
3961
|
+
tableName: __privateGet$3(this, _table),
|
3848
3962
|
recordId
|
3849
3963
|
},
|
3850
3964
|
body: record,
|
3851
3965
|
queryParams: { createOnly, columns, ifVersion },
|
3852
|
-
...__privateGet$
|
3966
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3853
3967
|
});
|
3854
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3855
|
-
return initObject(__privateGet$
|
3968
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3969
|
+
return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
|
3856
3970
|
};
|
3857
3971
|
_insertRecords = new WeakSet();
|
3858
3972
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
3859
3973
|
const operations = await promiseMap(objects, async (object) => {
|
3860
3974
|
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3861
|
-
return { insert: { table: __privateGet$
|
3975
|
+
return { insert: { table: __privateGet$3(this, _table), record, createOnly, ifVersion } };
|
3862
3976
|
});
|
3863
3977
|
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
3864
3978
|
const ids = [];
|
@@ -3870,7 +3984,7 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
3870
3984
|
region: "{region}"
|
3871
3985
|
},
|
3872
3986
|
body: { operations: operations2 },
|
3873
|
-
...__privateGet$
|
3987
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3874
3988
|
});
|
3875
3989
|
for (const result of results) {
|
3876
3990
|
if (result.operation === "insert") {
|
@@ -3893,15 +4007,15 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
3893
4007
|
workspace: "{workspaceId}",
|
3894
4008
|
dbBranchName: "{dbBranch}",
|
3895
4009
|
region: "{region}",
|
3896
|
-
tableName: __privateGet$
|
4010
|
+
tableName: __privateGet$3(this, _table),
|
3897
4011
|
recordId
|
3898
4012
|
},
|
3899
4013
|
queryParams: { columns, ifVersion },
|
3900
4014
|
body: record,
|
3901
|
-
...__privateGet$
|
4015
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3902
4016
|
});
|
3903
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3904
|
-
return initObject(__privateGet$
|
4017
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
4018
|
+
return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
|
3905
4019
|
} catch (e) {
|
3906
4020
|
if (isObject(e) && e.status === 404) {
|
3907
4021
|
return null;
|
@@ -3913,7 +4027,7 @@ _updateRecords = new WeakSet();
|
|
3913
4027
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
3914
4028
|
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
3915
4029
|
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3916
|
-
return { update: { table: __privateGet$
|
4030
|
+
return { update: { table: __privateGet$3(this, _table), id, ifVersion, upsert, fields } };
|
3917
4031
|
});
|
3918
4032
|
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
3919
4033
|
const ids = [];
|
@@ -3925,7 +4039,7 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
3925
4039
|
region: "{region}"
|
3926
4040
|
},
|
3927
4041
|
body: { operations: operations2 },
|
3928
|
-
...__privateGet$
|
4042
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3929
4043
|
});
|
3930
4044
|
for (const result of results) {
|
3931
4045
|
if (result.operation === "update") {
|
@@ -3946,15 +4060,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
3946
4060
|
workspace: "{workspaceId}",
|
3947
4061
|
dbBranchName: "{dbBranch}",
|
3948
4062
|
region: "{region}",
|
3949
|
-
tableName: __privateGet$
|
4063
|
+
tableName: __privateGet$3(this, _table),
|
3950
4064
|
recordId
|
3951
4065
|
},
|
3952
4066
|
queryParams: { columns, ifVersion },
|
3953
4067
|
body: object,
|
3954
|
-
...__privateGet$
|
4068
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3955
4069
|
});
|
3956
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3957
|
-
return initObject(__privateGet$
|
4070
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
4071
|
+
return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
|
3958
4072
|
};
|
3959
4073
|
_deleteRecord = new WeakSet();
|
3960
4074
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
@@ -3966,14 +4080,14 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
3966
4080
|
workspace: "{workspaceId}",
|
3967
4081
|
dbBranchName: "{dbBranch}",
|
3968
4082
|
region: "{region}",
|
3969
|
-
tableName: __privateGet$
|
4083
|
+
tableName: __privateGet$3(this, _table),
|
3970
4084
|
recordId
|
3971
4085
|
},
|
3972
4086
|
queryParams: { columns },
|
3973
|
-
...__privateGet$
|
4087
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3974
4088
|
});
|
3975
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3976
|
-
return initObject(__privateGet$
|
4089
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
4090
|
+
return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
|
3977
4091
|
} catch (e) {
|
3978
4092
|
if (isObject(e) && e.status === 404) {
|
3979
4093
|
return null;
|
@@ -3984,7 +4098,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
3984
4098
|
_deleteRecords = new WeakSet();
|
3985
4099
|
deleteRecords_fn = async function(recordIds) {
|
3986
4100
|
const chunkedOperations = chunk(
|
3987
|
-
compact(recordIds).map((id) => ({ delete: { table: __privateGet$
|
4101
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$3(this, _table), id } })),
|
3988
4102
|
BULK_OPERATION_MAX_SIZE
|
3989
4103
|
);
|
3990
4104
|
for (const operations of chunkedOperations) {
|
@@ -3995,44 +4109,44 @@ deleteRecords_fn = async function(recordIds) {
|
|
3995
4109
|
region: "{region}"
|
3996
4110
|
},
|
3997
4111
|
body: { operations },
|
3998
|
-
...__privateGet$
|
4112
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3999
4113
|
});
|
4000
4114
|
}
|
4001
4115
|
};
|
4002
4116
|
_setCacheQuery = new WeakSet();
|
4003
4117
|
setCacheQuery_fn = async function(query, meta, records) {
|
4004
|
-
await __privateGet$
|
4118
|
+
await __privateGet$3(this, _cache)?.set(`query_${__privateGet$3(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
4005
4119
|
};
|
4006
4120
|
_getCacheQuery = new WeakSet();
|
4007
4121
|
getCacheQuery_fn = async function(query) {
|
4008
|
-
const key = `query_${__privateGet$
|
4009
|
-
const result = await __privateGet$
|
4122
|
+
const key = `query_${__privateGet$3(this, _table)}:${query.key()}`;
|
4123
|
+
const result = await __privateGet$3(this, _cache)?.get(key);
|
4010
4124
|
if (!result)
|
4011
4125
|
return null;
|
4012
|
-
const defaultTTL = __privateGet$
|
4126
|
+
const defaultTTL = __privateGet$3(this, _cache)?.defaultQueryTTL ?? -1;
|
4013
4127
|
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
4014
4128
|
if (ttl < 0)
|
4015
4129
|
return null;
|
4016
4130
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
4017
4131
|
return hasExpired ? null : result;
|
4018
4132
|
};
|
4019
|
-
_getSchemaTables
|
4020
|
-
getSchemaTables_fn
|
4021
|
-
if (__privateGet$
|
4022
|
-
return __privateGet$
|
4133
|
+
_getSchemaTables = new WeakSet();
|
4134
|
+
getSchemaTables_fn = async function() {
|
4135
|
+
if (__privateGet$3(this, _schemaTables))
|
4136
|
+
return __privateGet$3(this, _schemaTables);
|
4023
4137
|
const { schema } = await getBranchDetails({
|
4024
4138
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4025
|
-
...__privateGet$
|
4139
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
4026
4140
|
});
|
4027
|
-
__privateSet$
|
4141
|
+
__privateSet$2(this, _schemaTables, schema.tables);
|
4028
4142
|
return schema.tables;
|
4029
4143
|
};
|
4030
4144
|
_transformObjectToApi = new WeakSet();
|
4031
4145
|
transformObjectToApi_fn = async function(object) {
|
4032
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
4033
|
-
const schema = schemaTables.find((table) => table.name === __privateGet$
|
4146
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
4147
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$3(this, _table));
|
4034
4148
|
if (!schema)
|
4035
|
-
throw new Error(`Table ${__privateGet$
|
4149
|
+
throw new Error(`Table ${__privateGet$3(this, _table)} not found in schema`);
|
4036
4150
|
const result = {};
|
4037
4151
|
for (const [key, value] of Object.entries(object)) {
|
4038
4152
|
if (key === "xata")
|
@@ -4188,7 +4302,7 @@ var __accessCheck$3 = (obj, member, msg) => {
|
|
4188
4302
|
if (!member.has(obj))
|
4189
4303
|
throw TypeError("Cannot " + msg);
|
4190
4304
|
};
|
4191
|
-
var __privateGet$
|
4305
|
+
var __privateGet$2 = (obj, member, getter) => {
|
4192
4306
|
__accessCheck$3(obj, member, "read from private field");
|
4193
4307
|
return getter ? getter.call(obj) : member.get(obj);
|
4194
4308
|
};
|
@@ -4197,7 +4311,7 @@ var __privateAdd$3 = (obj, member, value) => {
|
|
4197
4311
|
throw TypeError("Cannot add the same private member more than once");
|
4198
4312
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
4199
4313
|
};
|
4200
|
-
var __privateSet$
|
4314
|
+
var __privateSet$1 = (obj, member, value, setter) => {
|
4201
4315
|
__accessCheck$3(obj, member, "write to private field");
|
4202
4316
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
4203
4317
|
return value;
|
@@ -4206,29 +4320,29 @@ var _map;
|
|
4206
4320
|
class SimpleCache {
|
4207
4321
|
constructor(options = {}) {
|
4208
4322
|
__privateAdd$3(this, _map, void 0);
|
4209
|
-
__privateSet$
|
4323
|
+
__privateSet$1(this, _map, /* @__PURE__ */ new Map());
|
4210
4324
|
this.capacity = options.max ?? 500;
|
4211
4325
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
4212
4326
|
}
|
4213
4327
|
async getAll() {
|
4214
|
-
return Object.fromEntries(__privateGet$
|
4328
|
+
return Object.fromEntries(__privateGet$2(this, _map));
|
4215
4329
|
}
|
4216
4330
|
async get(key) {
|
4217
|
-
return __privateGet$
|
4331
|
+
return __privateGet$2(this, _map).get(key) ?? null;
|
4218
4332
|
}
|
4219
4333
|
async set(key, value) {
|
4220
4334
|
await this.delete(key);
|
4221
|
-
__privateGet$
|
4222
|
-
if (__privateGet$
|
4223
|
-
const leastRecentlyUsed = __privateGet$
|
4335
|
+
__privateGet$2(this, _map).set(key, value);
|
4336
|
+
if (__privateGet$2(this, _map).size > this.capacity) {
|
4337
|
+
const leastRecentlyUsed = __privateGet$2(this, _map).keys().next().value;
|
4224
4338
|
await this.delete(leastRecentlyUsed);
|
4225
4339
|
}
|
4226
4340
|
}
|
4227
4341
|
async delete(key) {
|
4228
|
-
__privateGet$
|
4342
|
+
__privateGet$2(this, _map).delete(key);
|
4229
4343
|
}
|
4230
4344
|
async clear() {
|
4231
|
-
return __privateGet$
|
4345
|
+
return __privateGet$2(this, _map).clear();
|
4232
4346
|
}
|
4233
4347
|
}
|
4234
4348
|
_map = new WeakMap();
|
@@ -4265,7 +4379,7 @@ var __accessCheck$2 = (obj, member, msg) => {
|
|
4265
4379
|
if (!member.has(obj))
|
4266
4380
|
throw TypeError("Cannot " + msg);
|
4267
4381
|
};
|
4268
|
-
var __privateGet$
|
4382
|
+
var __privateGet$1 = (obj, member, getter) => {
|
4269
4383
|
__accessCheck$2(obj, member, "read from private field");
|
4270
4384
|
return getter ? getter.call(obj) : member.get(obj);
|
4271
4385
|
};
|
@@ -4274,18 +4388,11 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
4274
4388
|
throw TypeError("Cannot add the same private member more than once");
|
4275
4389
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
4276
4390
|
};
|
4277
|
-
var
|
4278
|
-
__accessCheck$2(obj, member, "write to private field");
|
4279
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
4280
|
-
return value;
|
4281
|
-
};
|
4282
|
-
var _tables, _schemaTables$1;
|
4391
|
+
var _tables;
|
4283
4392
|
class SchemaPlugin extends XataPlugin {
|
4284
|
-
constructor(
|
4393
|
+
constructor() {
|
4285
4394
|
super();
|
4286
4395
|
__privateAdd$2(this, _tables, {});
|
4287
|
-
__privateAdd$2(this, _schemaTables$1, void 0);
|
4288
|
-
__privateSet$2(this, _schemaTables$1, schemaTables);
|
4289
4396
|
}
|
4290
4397
|
build(pluginOptions) {
|
4291
4398
|
const db = new Proxy(
|
@@ -4294,22 +4401,21 @@ class SchemaPlugin extends XataPlugin {
|
|
4294
4401
|
get: (_target, table) => {
|
4295
4402
|
if (!isString(table))
|
4296
4403
|
throw new Error("Invalid table name");
|
4297
|
-
if (__privateGet$
|
4298
|
-
__privateGet$
|
4404
|
+
if (__privateGet$1(this, _tables)[table] === void 0) {
|
4405
|
+
__privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: pluginOptions.tables });
|
4299
4406
|
}
|
4300
|
-
return __privateGet$
|
4407
|
+
return __privateGet$1(this, _tables)[table];
|
4301
4408
|
}
|
4302
4409
|
}
|
4303
4410
|
);
|
4304
|
-
const tableNames =
|
4411
|
+
const tableNames = pluginOptions.tables?.map(({ name }) => name) ?? [];
|
4305
4412
|
for (const table of tableNames) {
|
4306
|
-
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables:
|
4413
|
+
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: pluginOptions.tables });
|
4307
4414
|
}
|
4308
4415
|
return db;
|
4309
4416
|
}
|
4310
4417
|
}
|
4311
4418
|
_tables = new WeakMap();
|
4312
|
-
_schemaTables$1 = new WeakMap();
|
4313
4419
|
|
4314
4420
|
class FilesPlugin extends XataPlugin {
|
4315
4421
|
build(pluginOptions) {
|
@@ -4372,7 +4478,7 @@ function getContentType(file) {
|
|
4372
4478
|
if (typeof file === "string") {
|
4373
4479
|
return "text/plain";
|
4374
4480
|
}
|
4375
|
-
if ("mediaType" in file) {
|
4481
|
+
if ("mediaType" in file && file.mediaType !== void 0) {
|
4376
4482
|
return file.mediaType;
|
4377
4483
|
}
|
4378
4484
|
if (isBlob(file)) {
|
@@ -4389,54 +4495,40 @@ var __accessCheck$1 = (obj, member, msg) => {
|
|
4389
4495
|
if (!member.has(obj))
|
4390
4496
|
throw TypeError("Cannot " + msg);
|
4391
4497
|
};
|
4392
|
-
var __privateGet$1 = (obj, member, getter) => {
|
4393
|
-
__accessCheck$1(obj, member, "read from private field");
|
4394
|
-
return getter ? getter.call(obj) : member.get(obj);
|
4395
|
-
};
|
4396
4498
|
var __privateAdd$1 = (obj, member, value) => {
|
4397
4499
|
if (member.has(obj))
|
4398
4500
|
throw TypeError("Cannot add the same private member more than once");
|
4399
4501
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
4400
4502
|
};
|
4401
|
-
var __privateSet$1 = (obj, member, value, setter) => {
|
4402
|
-
__accessCheck$1(obj, member, "write to private field");
|
4403
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
4404
|
-
return value;
|
4405
|
-
};
|
4406
4503
|
var __privateMethod$1 = (obj, member, method) => {
|
4407
4504
|
__accessCheck$1(obj, member, "access private method");
|
4408
4505
|
return method;
|
4409
4506
|
};
|
4410
|
-
var
|
4507
|
+
var _search, search_fn;
|
4411
4508
|
class SearchPlugin extends XataPlugin {
|
4412
|
-
constructor(db
|
4509
|
+
constructor(db) {
|
4413
4510
|
super();
|
4414
4511
|
this.db = db;
|
4415
4512
|
__privateAdd$1(this, _search);
|
4416
|
-
__privateAdd$1(this, _getSchemaTables);
|
4417
|
-
__privateAdd$1(this, _schemaTables, void 0);
|
4418
|
-
__privateSet$1(this, _schemaTables, schemaTables);
|
4419
4513
|
}
|
4420
4514
|
build(pluginOptions) {
|
4421
4515
|
return {
|
4422
4516
|
all: async (query, options = {}) => {
|
4423
4517
|
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4424
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4425
4518
|
return {
|
4426
4519
|
totalCount,
|
4427
4520
|
records: records.map((record) => {
|
4428
4521
|
const { table = "orphan" } = record.xata;
|
4429
|
-
return { table, record: initObject(this.db,
|
4522
|
+
return { table, record: initObject(this.db, pluginOptions.tables, table, record, ["*"]) };
|
4430
4523
|
})
|
4431
4524
|
};
|
4432
4525
|
},
|
4433
4526
|
byTable: async (query, options = {}) => {
|
4434
4527
|
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4435
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4436
4528
|
const records = rawRecords.reduce((acc, record) => {
|
4437
4529
|
const { table = "orphan" } = record.xata;
|
4438
4530
|
const items = acc[table] ?? [];
|
4439
|
-
const item = initObject(this.db,
|
4531
|
+
const item = initObject(this.db, pluginOptions.tables, table, record, ["*"]);
|
4440
4532
|
return { ...acc, [table]: [...items, item] };
|
4441
4533
|
}, {});
|
4442
4534
|
return { totalCount, records };
|
@@ -4444,29 +4536,17 @@ class SearchPlugin extends XataPlugin {
|
|
4444
4536
|
};
|
4445
4537
|
}
|
4446
4538
|
}
|
4447
|
-
_schemaTables = new WeakMap();
|
4448
4539
|
_search = new WeakSet();
|
4449
4540
|
search_fn = async function(query, options, pluginOptions) {
|
4450
4541
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
4451
4542
|
const { records, totalCount } = await searchBranch({
|
4452
4543
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4453
|
-
// @ts-
|
4544
|
+
// @ts-expect-error Filter properties do not match inferred type
|
4454
4545
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
4455
4546
|
...pluginOptions
|
4456
4547
|
});
|
4457
4548
|
return { records, totalCount };
|
4458
4549
|
};
|
4459
|
-
_getSchemaTables = new WeakSet();
|
4460
|
-
getSchemaTables_fn = async function(pluginOptions) {
|
4461
|
-
if (__privateGet$1(this, _schemaTables))
|
4462
|
-
return __privateGet$1(this, _schemaTables);
|
4463
|
-
const { schema } = await getBranchDetails({
|
4464
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4465
|
-
...pluginOptions
|
4466
|
-
});
|
4467
|
-
__privateSet$1(this, _schemaTables, schema.tables);
|
4468
|
-
return schema.tables;
|
4469
|
-
};
|
4470
4550
|
|
4471
4551
|
function escapeElement(elementRepresentation) {
|
4472
4552
|
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
@@ -4520,25 +4600,68 @@ function prepareParams(param1, param2) {
|
|
4520
4600
|
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
4521
4601
|
}
|
4522
4602
|
if (isObject(param1)) {
|
4523
|
-
const { statement, params, consistency } = param1;
|
4524
|
-
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
4603
|
+
const { statement, params, consistency, responseType } = param1;
|
4604
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency, responseType };
|
4525
4605
|
}
|
4526
4606
|
throw new Error("Invalid query");
|
4527
4607
|
}
|
4528
4608
|
|
4529
4609
|
class SQLPlugin extends XataPlugin {
|
4530
4610
|
build(pluginOptions) {
|
4531
|
-
|
4532
|
-
|
4533
|
-
|
4611
|
+
const sqlFunction = async (query, ...parameters) => {
|
4612
|
+
if (!isParamsObject(query) && (!isTemplateStringsArray(query) || !Array.isArray(parameters))) {
|
4613
|
+
throw new Error("Invalid usage of `xata.sql`. Please use it as a tagged template or with an object.");
|
4614
|
+
}
|
4615
|
+
const { statement, params, consistency, responseType } = prepareParams(query, parameters);
|
4616
|
+
const {
|
4617
|
+
records,
|
4618
|
+
rows,
|
4619
|
+
warning,
|
4620
|
+
columns = []
|
4621
|
+
} = await sqlQuery({
|
4534
4622
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4535
|
-
body: { statement, params, consistency },
|
4623
|
+
body: { statement, params, consistency, responseType },
|
4536
4624
|
...pluginOptions
|
4537
4625
|
});
|
4538
|
-
return { records, warning };
|
4626
|
+
return { records, rows, warning, columns };
|
4539
4627
|
};
|
4628
|
+
sqlFunction.connectionString = buildConnectionString(pluginOptions);
|
4629
|
+
return sqlFunction;
|
4540
4630
|
}
|
4541
4631
|
}
|
4632
|
+
function isTemplateStringsArray(strings) {
|
4633
|
+
return Array.isArray(strings) && "raw" in strings && Array.isArray(strings.raw);
|
4634
|
+
}
|
4635
|
+
function isParamsObject(params) {
|
4636
|
+
return isObject(params) && "statement" in params;
|
4637
|
+
}
|
4638
|
+
function buildDomain(host, region) {
|
4639
|
+
switch (host) {
|
4640
|
+
case "production":
|
4641
|
+
return `${region}.sql.xata.sh`;
|
4642
|
+
case "staging":
|
4643
|
+
return `${region}.sql.staging-xata.dev`;
|
4644
|
+
case "dev":
|
4645
|
+
return `${region}.sql.dev-xata.dev`;
|
4646
|
+
case "local":
|
4647
|
+
return "localhost:7654";
|
4648
|
+
default:
|
4649
|
+
throw new Error("Invalid host provider");
|
4650
|
+
}
|
4651
|
+
}
|
4652
|
+
function buildConnectionString({ apiKey, workspacesApiUrl, branch }) {
|
4653
|
+
const url = isString(workspacesApiUrl) ? workspacesApiUrl : workspacesApiUrl("", {});
|
4654
|
+
const parts = parseWorkspacesUrlParts(url);
|
4655
|
+
if (!parts)
|
4656
|
+
throw new Error("Invalid workspaces URL");
|
4657
|
+
const { workspace: workspaceSlug, region, database, host } = parts;
|
4658
|
+
const domain = buildDomain(host, region);
|
4659
|
+
const workspace = workspaceSlug.split("-").pop();
|
4660
|
+
if (!workspace || !region || !database || !apiKey || !branch) {
|
4661
|
+
throw new Error("Unable to build xata connection string");
|
4662
|
+
}
|
4663
|
+
return `postgresql://${workspace}:${apiKey}@${domain}/${database}:${branch}?sslmode=require`;
|
4664
|
+
}
|
4542
4665
|
|
4543
4666
|
class TransactionPlugin extends XataPlugin {
|
4544
4667
|
build(pluginOptions) {
|
@@ -4580,7 +4703,7 @@ var __privateMethod = (obj, member, method) => {
|
|
4580
4703
|
const buildClient = (plugins) => {
|
4581
4704
|
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
4582
4705
|
return _a = class {
|
4583
|
-
constructor(options = {},
|
4706
|
+
constructor(options = {}, tables) {
|
4584
4707
|
__privateAdd(this, _parseOptions);
|
4585
4708
|
__privateAdd(this, _getFetchProps);
|
4586
4709
|
__privateAdd(this, _options, void 0);
|
@@ -4589,13 +4712,16 @@ const buildClient = (plugins) => {
|
|
4589
4712
|
const pluginOptions = {
|
4590
4713
|
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
4591
4714
|
cache: safeOptions.cache,
|
4592
|
-
host: safeOptions.host
|
4715
|
+
host: safeOptions.host,
|
4716
|
+
tables,
|
4717
|
+
branch: safeOptions.branch
|
4593
4718
|
};
|
4594
|
-
const db = new SchemaPlugin(
|
4595
|
-
const search = new SearchPlugin(db
|
4719
|
+
const db = new SchemaPlugin().build(pluginOptions);
|
4720
|
+
const search = new SearchPlugin(db).build(pluginOptions);
|
4596
4721
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4597
4722
|
const sql = new SQLPlugin().build(pluginOptions);
|
4598
4723
|
const files = new FilesPlugin().build(pluginOptions);
|
4724
|
+
this.schema = { tables };
|
4599
4725
|
this.db = db;
|
4600
4726
|
this.search = search;
|
4601
4727
|
this.transactions = transactions;
|
@@ -4617,7 +4743,7 @@ const buildClient = (plugins) => {
|
|
4617
4743
|
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
4618
4744
|
if (isBrowser && !enableBrowser) {
|
4619
4745
|
throw new Error(
|
4620
|
-
"You are trying to use Xata from the browser, which is potentially a non-secure environment.
|
4746
|
+
"You are trying to use Xata from the browser, which is potentially a non-secure environment. How to fix: https://xata.io/docs/messages/api-key-browser-error"
|
4621
4747
|
);
|
4622
4748
|
}
|
4623
4749
|
const fetch = getFetchImplementation(options?.fetch);
|
@@ -4780,6 +4906,7 @@ exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
|
|
4780
4906
|
exports.PAGINATION_MAX_OFFSET = PAGINATION_MAX_OFFSET;
|
4781
4907
|
exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
|
4782
4908
|
exports.Page = Page;
|
4909
|
+
exports.PageRecordArray = PageRecordArray;
|
4783
4910
|
exports.Query = Query;
|
4784
4911
|
exports.RecordArray = RecordArray;
|
4785
4912
|
exports.RecordColumnTypes = RecordColumnTypes;
|
@@ -4797,6 +4924,8 @@ exports.XataError = XataError;
|
|
4797
4924
|
exports.XataFile = XataFile;
|
4798
4925
|
exports.XataPlugin = XataPlugin;
|
4799
4926
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
4927
|
+
exports.adaptAllTables = adaptAllTables;
|
4928
|
+
exports.adaptTable = adaptTable;
|
4800
4929
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
4801
4930
|
exports.addTableColumn = addTableColumn;
|
4802
4931
|
exports.aggregateTable = aggregateTable;
|
@@ -4841,6 +4970,7 @@ exports.equals = equals;
|
|
4841
4970
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
4842
4971
|
exports.exists = exists;
|
4843
4972
|
exports.fileAccess = fileAccess;
|
4973
|
+
exports.fileUpload = fileUpload;
|
4844
4974
|
exports.ge = ge;
|
4845
4975
|
exports.getAPIKey = getAPIKey;
|
4846
4976
|
exports.getAuthorizationCode = getAuthorizationCode;
|
@@ -4849,6 +4979,7 @@ exports.getBranchDetails = getBranchDetails;
|
|
4849
4979
|
exports.getBranchList = getBranchList;
|
4850
4980
|
exports.getBranchMetadata = getBranchMetadata;
|
4851
4981
|
exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
4982
|
+
exports.getBranchMigrationJobStatus = getBranchMigrationJobStatus;
|
4852
4983
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
4853
4984
|
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
4854
4985
|
exports.getBranchStats = getBranchStats;
|
@@ -4857,11 +4988,14 @@ exports.getColumn = getColumn;
|
|
4857
4988
|
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
4858
4989
|
exports.getDatabaseList = getDatabaseList;
|
4859
4990
|
exports.getDatabaseMetadata = getDatabaseMetadata;
|
4991
|
+
exports.getDatabaseSettings = getDatabaseSettings;
|
4860
4992
|
exports.getDatabaseURL = getDatabaseURL;
|
4861
4993
|
exports.getFile = getFile;
|
4862
4994
|
exports.getFileItem = getFileItem;
|
4863
4995
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
4864
4996
|
exports.getHostUrl = getHostUrl;
|
4997
|
+
exports.getMigrationHistory = getMigrationHistory;
|
4998
|
+
exports.getMigrationJobStatus = getMigrationJobStatus;
|
4865
4999
|
exports.getMigrationRequest = getMigrationRequest;
|
4866
5000
|
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
4867
5001
|
exports.getPreviewBranch = getPreviewBranch;
|
@@ -4875,6 +5009,7 @@ exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
|
|
4875
5009
|
exports.getUserOAuthClients = getUserOAuthClients;
|
4876
5010
|
exports.getWorkspace = getWorkspace;
|
4877
5011
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
5012
|
+
exports.getWorkspaceSettings = getWorkspaceSettings;
|
4878
5013
|
exports.getWorkspacesList = getWorkspacesList;
|
4879
5014
|
exports.grantAuthorizationCode = grantAuthorizationCode;
|
4880
5015
|
exports.greaterEquals = greaterEquals;
|
@@ -4915,7 +5050,6 @@ exports.operationsByTag = operationsByTag;
|
|
4915
5050
|
exports.parseProviderString = parseProviderString;
|
4916
5051
|
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
4917
5052
|
exports.pattern = pattern;
|
4918
|
-
exports.pgRollStatus = pgRollStatus;
|
4919
5053
|
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
4920
5054
|
exports.pushBranchMigrations = pushBranchMigrations;
|
4921
5055
|
exports.putFile = putFile;
|
@@ -4941,6 +5075,7 @@ exports.updateCluster = updateCluster;
|
|
4941
5075
|
exports.updateColumn = updateColumn;
|
4942
5076
|
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
4943
5077
|
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
5078
|
+
exports.updateDatabaseSettings = updateDatabaseSettings;
|
4944
5079
|
exports.updateMigrationRequest = updateMigrationRequest;
|
4945
5080
|
exports.updateOAuthAccessToken = updateOAuthAccessToken;
|
4946
5081
|
exports.updateRecordWithID = updateRecordWithID;
|
@@ -4949,6 +5084,7 @@ exports.updateUser = updateUser;
|
|
4949
5084
|
exports.updateWorkspace = updateWorkspace;
|
4950
5085
|
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
4951
5086
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
5087
|
+
exports.updateWorkspaceSettings = updateWorkspaceSettings;
|
4952
5088
|
exports.upsertRecordWithID = upsertRecordWithID;
|
4953
5089
|
exports.vectorSearchTable = vectorSearchTable;
|
4954
5090
|
//# sourceMappingURL=index.cjs.map
|