@xata.io/client 0.0.0-alpha.vf181bf6b5770b15d42125b2728f3bf80a87e6333 → 0.0.0-alpha.vf1f4a0ec9618ca20e1909d6f4c7de0b61531b7e1
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 +55 -1
- package/dist/index.cjs +444 -488
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3169 -2740
- package/dist/index.mjs +437 -485
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -244,26 +244,26 @@ function getPreviewBranch() {
|
|
244
244
|
}
|
245
245
|
}
|
246
246
|
|
247
|
-
var __accessCheck$
|
247
|
+
var __accessCheck$6 = (obj, member, msg) => {
|
248
248
|
if (!member.has(obj))
|
249
249
|
throw TypeError("Cannot " + msg);
|
250
250
|
};
|
251
|
-
var __privateGet$
|
252
|
-
__accessCheck$
|
251
|
+
var __privateGet$5 = (obj, member, getter) => {
|
252
|
+
__accessCheck$6(obj, member, "read from private field");
|
253
253
|
return getter ? getter.call(obj) : member.get(obj);
|
254
254
|
};
|
255
|
-
var __privateAdd$
|
255
|
+
var __privateAdd$6 = (obj, member, value) => {
|
256
256
|
if (member.has(obj))
|
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$
|
261
|
-
__accessCheck$
|
260
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
261
|
+
__accessCheck$6(obj, member, "write to private field");
|
262
262
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
263
263
|
return value;
|
264
264
|
};
|
265
265
|
var __privateMethod$4 = (obj, member, method) => {
|
266
|
-
__accessCheck$
|
266
|
+
__accessCheck$6(obj, member, "access private method");
|
267
267
|
return method;
|
268
268
|
};
|
269
269
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
@@ -279,23 +279,23 @@ function getFetchImplementation(userFetch) {
|
|
279
279
|
}
|
280
280
|
class ApiRequestPool {
|
281
281
|
constructor(concurrency = 10) {
|
282
|
-
__privateAdd$
|
283
|
-
__privateAdd$
|
284
|
-
__privateAdd$
|
285
|
-
__privateAdd$
|
286
|
-
__privateSet$
|
287
|
-
__privateSet$
|
282
|
+
__privateAdd$6(this, _enqueue);
|
283
|
+
__privateAdd$6(this, _fetch, void 0);
|
284
|
+
__privateAdd$6(this, _queue, void 0);
|
285
|
+
__privateAdd$6(this, _concurrency, void 0);
|
286
|
+
__privateSet$4(this, _queue, []);
|
287
|
+
__privateSet$4(this, _concurrency, concurrency);
|
288
288
|
this.running = 0;
|
289
289
|
this.started = 0;
|
290
290
|
}
|
291
291
|
setFetch(fetch2) {
|
292
|
-
__privateSet$
|
292
|
+
__privateSet$4(this, _fetch, fetch2);
|
293
293
|
}
|
294
294
|
getFetch() {
|
295
|
-
if (!__privateGet$
|
295
|
+
if (!__privateGet$5(this, _fetch)) {
|
296
296
|
throw new Error("Fetch not set");
|
297
297
|
}
|
298
|
-
return __privateGet$
|
298
|
+
return __privateGet$5(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$5(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$5(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$5(this, _concurrency)) {
|
342
|
+
const next = __privateGet$5(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.2";
|
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.*/),
|
625
|
+
staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
|
626
|
+
dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/),
|
627
|
+
local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(\d+)/)
|
628
|
+
};
|
629
|
+
const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
|
630
|
+
if (!isHostProviderAlias(host) || !match)
|
631
|
+
return null;
|
632
|
+
return { workspace: match[1], region: match[2], host };
|
633
|
+
}
|
634
|
+
|
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)
|
@@ -661,6 +740,8 @@ async function fetch$1({
|
|
661
740
|
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
662
741
|
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
663
742
|
"X-Xata-Agent": xataAgent,
|
743
|
+
// Force field rename to xata_ internal properties
|
744
|
+
"X-Features": compact(["feat-internal-field-rename-api=1", customHeaders?.["X-Features"]]).join(" "),
|
664
745
|
...customHeaders,
|
665
746
|
...hostHeader(fullUrl),
|
666
747
|
Authorization: `Bearer ${apiKey}`
|
@@ -725,7 +806,7 @@ function fetchSSERequest({
|
|
725
806
|
clientName,
|
726
807
|
xataAgentExtra
|
727
808
|
}) {
|
728
|
-
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
809
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
729
810
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
730
811
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
731
812
|
void fetchEventSource(url, {
|
@@ -768,25 +849,29 @@ function parseUrl(url) {
|
|
768
849
|
|
769
850
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
770
851
|
|
771
|
-
const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/
|
772
|
-
const
|
773
|
-
url: "/db/{dbBranchName}/
|
774
|
-
method: "
|
852
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/apply", method: "post", ...variables, signal });
|
853
|
+
const adaptTable = (variables, signal) => dataPlaneFetch({
|
854
|
+
url: "/db/{dbBranchName}/migrations/adapt/{tableName}",
|
855
|
+
method: "post",
|
775
856
|
...variables,
|
776
857
|
signal
|
777
858
|
});
|
778
|
-
const
|
779
|
-
|
859
|
+
const getBranchMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/status", method: "get", ...variables, signal });
|
860
|
+
const getMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/jobs/{jobId}", method: "get", ...variables, signal });
|
861
|
+
const getMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/history", method: "get", ...variables, signal });
|
862
|
+
const getBranchList = (variables, signal) => dataPlaneFetch({
|
863
|
+
url: "/dbs/{dbName}",
|
780
864
|
method: "get",
|
781
865
|
...variables,
|
782
866
|
signal
|
783
867
|
});
|
784
|
-
const
|
785
|
-
url: "/dbs/{dbName}",
|
868
|
+
const getDatabaseSettings = (variables, signal) => dataPlaneFetch({
|
869
|
+
url: "/dbs/{dbName}/settings",
|
786
870
|
method: "get",
|
787
871
|
...variables,
|
788
872
|
signal
|
789
873
|
});
|
874
|
+
const updateDatabaseSettings = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/settings", method: "patch", ...variables, signal });
|
790
875
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
791
876
|
url: "/db/{dbBranchName}",
|
792
877
|
method: "get",
|
@@ -987,6 +1072,12 @@ const fileAccess = (variables, signal) => dataPlaneFetch({
|
|
987
1072
|
...variables,
|
988
1073
|
signal
|
989
1074
|
});
|
1075
|
+
const fileUpload = (variables, signal) => dataPlaneFetch({
|
1076
|
+
url: "/file/{fileId}",
|
1077
|
+
method: "put",
|
1078
|
+
...variables,
|
1079
|
+
signal
|
1080
|
+
});
|
990
1081
|
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
991
1082
|
url: "/db/{dbBranchName}/sql",
|
992
1083
|
method: "post",
|
@@ -994,10 +1085,25 @@ const sqlQuery = (variables, signal) => dataPlaneFetch({
|
|
994
1085
|
signal
|
995
1086
|
});
|
996
1087
|
const operationsByTag$2 = {
|
997
|
-
|
1088
|
+
migrations: {
|
998
1089
|
applyMigration,
|
999
|
-
|
1000
|
-
|
1090
|
+
adaptTable,
|
1091
|
+
getBranchMigrationJobStatus,
|
1092
|
+
getMigrationJobStatus,
|
1093
|
+
getMigrationHistory,
|
1094
|
+
getSchema,
|
1095
|
+
getBranchMigrationHistory,
|
1096
|
+
getBranchMigrationPlan,
|
1097
|
+
executeBranchMigrationPlan,
|
1098
|
+
getBranchSchemaHistory,
|
1099
|
+
compareBranchWithUserSchema,
|
1100
|
+
compareBranchSchemas,
|
1101
|
+
updateBranchSchema,
|
1102
|
+
previewBranchSchemaEdit,
|
1103
|
+
applyBranchSchemaEdit,
|
1104
|
+
pushBranchMigrations
|
1105
|
+
},
|
1106
|
+
branch: {
|
1001
1107
|
getBranchList,
|
1002
1108
|
getBranchDetails,
|
1003
1109
|
createBranch,
|
@@ -1011,19 +1117,7 @@ const operationsByTag$2 = {
|
|
1011
1117
|
removeGitBranchesEntry,
|
1012
1118
|
resolveBranch
|
1013
1119
|
},
|
1014
|
-
|
1015
|
-
getSchema,
|
1016
|
-
getBranchMigrationHistory,
|
1017
|
-
getBranchMigrationPlan,
|
1018
|
-
executeBranchMigrationPlan,
|
1019
|
-
getBranchSchemaHistory,
|
1020
|
-
compareBranchWithUserSchema,
|
1021
|
-
compareBranchSchemas,
|
1022
|
-
updateBranchSchema,
|
1023
|
-
previewBranchSchemaEdit,
|
1024
|
-
applyBranchSchemaEdit,
|
1025
|
-
pushBranchMigrations
|
1026
|
-
},
|
1120
|
+
database: { getDatabaseSettings, updateDatabaseSettings },
|
1027
1121
|
migrationRequests: {
|
1028
1122
|
queryMigrationRequests,
|
1029
1123
|
createMigrationRequest,
|
@@ -1056,7 +1150,7 @@ const operationsByTag$2 = {
|
|
1056
1150
|
deleteRecord,
|
1057
1151
|
bulkInsertTableRecords
|
1058
1152
|
},
|
1059
|
-
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1153
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
|
1060
1154
|
searchAndFilter: {
|
1061
1155
|
queryTable,
|
1062
1156
|
searchBranch,
|
@@ -1178,12 +1272,7 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
|
|
1178
1272
|
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
1179
1273
|
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
1180
1274
|
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1181
|
-
const listClusters = (variables, signal) => controlPlaneFetch({
|
1182
|
-
url: "/workspaces/{workspaceId}/clusters",
|
1183
|
-
method: "get",
|
1184
|
-
...variables,
|
1185
|
-
signal
|
1186
|
-
});
|
1275
|
+
const listClusters = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "get", ...variables, signal });
|
1187
1276
|
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
1188
1277
|
const getCluster = (variables, signal) => controlPlaneFetch({
|
1189
1278
|
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
@@ -1263,61 +1352,6 @@ const operationsByTag$1 = {
|
|
1263
1352
|
|
1264
1353
|
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
1265
1354
|
|
1266
|
-
function getHostUrl(provider, type) {
|
1267
|
-
if (isHostProviderAlias(provider)) {
|
1268
|
-
return providers[provider][type];
|
1269
|
-
} else if (isHostProviderBuilder(provider)) {
|
1270
|
-
return provider[type];
|
1271
|
-
}
|
1272
|
-
throw new Error("Invalid API provider");
|
1273
|
-
}
|
1274
|
-
const providers = {
|
1275
|
-
production: {
|
1276
|
-
main: "https://api.xata.io",
|
1277
|
-
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
1278
|
-
},
|
1279
|
-
staging: {
|
1280
|
-
main: "https://api.staging-xata.dev",
|
1281
|
-
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1282
|
-
},
|
1283
|
-
dev: {
|
1284
|
-
main: "https://api.dev-xata.dev",
|
1285
|
-
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
1286
|
-
}
|
1287
|
-
};
|
1288
|
-
function isHostProviderAlias(alias) {
|
1289
|
-
return isString(alias) && Object.keys(providers).includes(alias);
|
1290
|
-
}
|
1291
|
-
function isHostProviderBuilder(builder) {
|
1292
|
-
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
1293
|
-
}
|
1294
|
-
function parseProviderString(provider = "production") {
|
1295
|
-
if (isHostProviderAlias(provider)) {
|
1296
|
-
return provider;
|
1297
|
-
}
|
1298
|
-
const [main, workspaces] = provider.split(",");
|
1299
|
-
if (!main || !workspaces)
|
1300
|
-
return null;
|
1301
|
-
return { main, workspaces };
|
1302
|
-
}
|
1303
|
-
function buildProviderString(provider) {
|
1304
|
-
if (isHostProviderAlias(provider))
|
1305
|
-
return provider;
|
1306
|
-
return `${provider.main},${provider.workspaces}`;
|
1307
|
-
}
|
1308
|
-
function parseWorkspacesUrlParts(url) {
|
1309
|
-
if (!isString(url))
|
1310
|
-
return null;
|
1311
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1312
|
-
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1313
|
-
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1314
|
-
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1315
|
-
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
1316
|
-
if (!match)
|
1317
|
-
return null;
|
1318
|
-
return { workspace: match[1], region: match[2] };
|
1319
|
-
}
|
1320
|
-
|
1321
1355
|
const buildApiClient = () => class {
|
1322
1356
|
constructor(options = {}) {
|
1323
1357
|
const provider = options.host ?? "production";
|
@@ -1408,10 +1442,12 @@ class XataFile {
|
|
1408
1442
|
this.base64Content = file.base64Content;
|
1409
1443
|
this.enablePublicUrl = file.enablePublicUrl;
|
1410
1444
|
this.signedUrlTimeout = file.signedUrlTimeout;
|
1445
|
+
this.uploadUrlTimeout = file.uploadUrlTimeout;
|
1411
1446
|
this.size = file.size;
|
1412
1447
|
this.version = file.version;
|
1413
1448
|
this.url = file.url;
|
1414
1449
|
this.signedUrl = file.signedUrl;
|
1450
|
+
this.uploadUrl = file.uploadUrl;
|
1415
1451
|
this.attributes = file.attributes;
|
1416
1452
|
}
|
1417
1453
|
static fromBuffer(buffer, options = {}) {
|
@@ -1502,7 +1538,7 @@ class XataFile {
|
|
1502
1538
|
const parseInputFileEntry = async (entry) => {
|
1503
1539
|
if (!isDefined(entry))
|
1504
1540
|
return null;
|
1505
|
-
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
1541
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
|
1506
1542
|
return compactObject({
|
1507
1543
|
id,
|
1508
1544
|
// Name cannot be an empty string in our API
|
@@ -1510,7 +1546,8 @@ const parseInputFileEntry = async (entry) => {
|
|
1510
1546
|
mediaType,
|
1511
1547
|
base64Content,
|
1512
1548
|
enablePublicUrl,
|
1513
|
-
signedUrlTimeout
|
1549
|
+
signedUrlTimeout,
|
1550
|
+
uploadUrlTimeout
|
1514
1551
|
});
|
1515
1552
|
};
|
1516
1553
|
|
@@ -1560,31 +1597,31 @@ function parseJson(value) {
|
|
1560
1597
|
}
|
1561
1598
|
}
|
1562
1599
|
|
1563
|
-
var __accessCheck$
|
1600
|
+
var __accessCheck$5 = (obj, member, msg) => {
|
1564
1601
|
if (!member.has(obj))
|
1565
1602
|
throw TypeError("Cannot " + msg);
|
1566
1603
|
};
|
1567
|
-
var __privateGet$
|
1568
|
-
__accessCheck$
|
1604
|
+
var __privateGet$4 = (obj, member, getter) => {
|
1605
|
+
__accessCheck$5(obj, member, "read from private field");
|
1569
1606
|
return getter ? getter.call(obj) : member.get(obj);
|
1570
1607
|
};
|
1571
|
-
var __privateAdd$
|
1608
|
+
var __privateAdd$5 = (obj, member, value) => {
|
1572
1609
|
if (member.has(obj))
|
1573
1610
|
throw TypeError("Cannot add the same private member more than once");
|
1574
1611
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1575
1612
|
};
|
1576
|
-
var __privateSet$
|
1577
|
-
__accessCheck$
|
1613
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
1614
|
+
__accessCheck$5(obj, member, "write to private field");
|
1578
1615
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1579
1616
|
return value;
|
1580
1617
|
};
|
1581
1618
|
var _query, _page;
|
1582
1619
|
class Page {
|
1583
1620
|
constructor(query, meta, records = []) {
|
1584
|
-
__privateAdd$
|
1585
|
-
__privateSet$
|
1621
|
+
__privateAdd$5(this, _query, void 0);
|
1622
|
+
__privateSet$3(this, _query, query);
|
1586
1623
|
this.meta = meta;
|
1587
|
-
this.records = new
|
1624
|
+
this.records = new PageRecordArray(this, records);
|
1588
1625
|
}
|
1589
1626
|
/**
|
1590
1627
|
* Retrieves the next page of results.
|
@@ -1593,7 +1630,7 @@ class Page {
|
|
1593
1630
|
* @returns The next page or results.
|
1594
1631
|
*/
|
1595
1632
|
async nextPage(size, offset) {
|
1596
|
-
return __privateGet$
|
1633
|
+
return __privateGet$4(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1597
1634
|
}
|
1598
1635
|
/**
|
1599
1636
|
* Retrieves the previous page of results.
|
@@ -1602,7 +1639,7 @@ class Page {
|
|
1602
1639
|
* @returns The previous page or results.
|
1603
1640
|
*/
|
1604
1641
|
async previousPage(size, offset) {
|
1605
|
-
return __privateGet$
|
1642
|
+
return __privateGet$4(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1606
1643
|
}
|
1607
1644
|
/**
|
1608
1645
|
* Retrieves the start page of results.
|
@@ -1611,7 +1648,7 @@ class Page {
|
|
1611
1648
|
* @returns The start page or results.
|
1612
1649
|
*/
|
1613
1650
|
async startPage(size, offset) {
|
1614
|
-
return __privateGet$
|
1651
|
+
return __privateGet$4(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1615
1652
|
}
|
1616
1653
|
/**
|
1617
1654
|
* Retrieves the end page of results.
|
@@ -1620,7 +1657,7 @@ class Page {
|
|
1620
1657
|
* @returns The end page or results.
|
1621
1658
|
*/
|
1622
1659
|
async endPage(size, offset) {
|
1623
|
-
return __privateGet$
|
1660
|
+
return __privateGet$4(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1624
1661
|
}
|
1625
1662
|
/**
|
1626
1663
|
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
@@ -1638,11 +1675,38 @@ const PAGINATION_DEFAULT_OFFSET = 0;
|
|
1638
1675
|
function isCursorPaginationOptions(options) {
|
1639
1676
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1640
1677
|
}
|
1641
|
-
|
1678
|
+
class RecordArray extends Array {
|
1679
|
+
constructor(...args) {
|
1680
|
+
super(...RecordArray.parseConstructorParams(...args));
|
1681
|
+
}
|
1682
|
+
static parseConstructorParams(...args) {
|
1683
|
+
if (args.length === 1 && typeof args[0] === "number") {
|
1684
|
+
return new Array(args[0]);
|
1685
|
+
}
|
1686
|
+
if (args.length <= 1 && Array.isArray(args[0] ?? [])) {
|
1687
|
+
const result = args[0] ?? [];
|
1688
|
+
return new Array(...result);
|
1689
|
+
}
|
1690
|
+
return new Array(...args);
|
1691
|
+
}
|
1692
|
+
toArray() {
|
1693
|
+
return new Array(...this);
|
1694
|
+
}
|
1695
|
+
toSerializable() {
|
1696
|
+
return JSON.parse(this.toString());
|
1697
|
+
}
|
1698
|
+
toString() {
|
1699
|
+
return JSON.stringify(this.toArray());
|
1700
|
+
}
|
1701
|
+
map(callbackfn, thisArg) {
|
1702
|
+
return this.toArray().map(callbackfn, thisArg);
|
1703
|
+
}
|
1704
|
+
}
|
1705
|
+
const _PageRecordArray = class _PageRecordArray extends Array {
|
1642
1706
|
constructor(...args) {
|
1643
|
-
super(...
|
1644
|
-
__privateAdd$
|
1645
|
-
__privateSet$
|
1707
|
+
super(..._PageRecordArray.parseConstructorParams(...args));
|
1708
|
+
__privateAdd$5(this, _page, void 0);
|
1709
|
+
__privateSet$3(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
1646
1710
|
}
|
1647
1711
|
static parseConstructorParams(...args) {
|
1648
1712
|
if (args.length === 1 && typeof args[0] === "number") {
|
@@ -1672,8 +1736,8 @@ const _RecordArray = class _RecordArray extends Array {
|
|
1672
1736
|
* @returns A new array of objects
|
1673
1737
|
*/
|
1674
1738
|
async nextPage(size, offset) {
|
1675
|
-
const newPage = await __privateGet$
|
1676
|
-
return new
|
1739
|
+
const newPage = await __privateGet$4(this, _page).nextPage(size, offset);
|
1740
|
+
return new _PageRecordArray(newPage);
|
1677
1741
|
}
|
1678
1742
|
/**
|
1679
1743
|
* Retrieve previous page of records
|
@@ -1681,8 +1745,8 @@ const _RecordArray = class _RecordArray extends Array {
|
|
1681
1745
|
* @returns A new array of objects
|
1682
1746
|
*/
|
1683
1747
|
async previousPage(size, offset) {
|
1684
|
-
const newPage = await __privateGet$
|
1685
|
-
return new
|
1748
|
+
const newPage = await __privateGet$4(this, _page).previousPage(size, offset);
|
1749
|
+
return new _PageRecordArray(newPage);
|
1686
1750
|
}
|
1687
1751
|
/**
|
1688
1752
|
* Retrieve start page of records
|
@@ -1690,8 +1754,8 @@ const _RecordArray = class _RecordArray extends Array {
|
|
1690
1754
|
* @returns A new array of objects
|
1691
1755
|
*/
|
1692
1756
|
async startPage(size, offset) {
|
1693
|
-
const newPage = await __privateGet$
|
1694
|
-
return new
|
1757
|
+
const newPage = await __privateGet$4(this, _page).startPage(size, offset);
|
1758
|
+
return new _PageRecordArray(newPage);
|
1695
1759
|
}
|
1696
1760
|
/**
|
1697
1761
|
* Retrieve end page of records
|
@@ -1699,69 +1763,68 @@ const _RecordArray = class _RecordArray extends Array {
|
|
1699
1763
|
* @returns A new array of objects
|
1700
1764
|
*/
|
1701
1765
|
async endPage(size, offset) {
|
1702
|
-
const newPage = await __privateGet$
|
1703
|
-
return new
|
1766
|
+
const newPage = await __privateGet$4(this, _page).endPage(size, offset);
|
1767
|
+
return new _PageRecordArray(newPage);
|
1704
1768
|
}
|
1705
1769
|
/**
|
1706
1770
|
* @returns Boolean indicating if there is a next page
|
1707
1771
|
*/
|
1708
1772
|
hasNextPage() {
|
1709
|
-
return __privateGet$
|
1773
|
+
return __privateGet$4(this, _page).meta.page.more;
|
1710
1774
|
}
|
1711
1775
|
};
|
1712
1776
|
_page = new WeakMap();
|
1713
|
-
let
|
1777
|
+
let PageRecordArray = _PageRecordArray;
|
1714
1778
|
|
1715
|
-
var __accessCheck$
|
1779
|
+
var __accessCheck$4 = (obj, member, msg) => {
|
1716
1780
|
if (!member.has(obj))
|
1717
1781
|
throw TypeError("Cannot " + msg);
|
1718
1782
|
};
|
1719
|
-
var __privateGet$
|
1720
|
-
__accessCheck$
|
1783
|
+
var __privateGet$3 = (obj, member, getter) => {
|
1784
|
+
__accessCheck$4(obj, member, "read from private field");
|
1721
1785
|
return getter ? getter.call(obj) : member.get(obj);
|
1722
1786
|
};
|
1723
|
-
var __privateAdd$
|
1787
|
+
var __privateAdd$4 = (obj, member, value) => {
|
1724
1788
|
if (member.has(obj))
|
1725
1789
|
throw TypeError("Cannot add the same private member more than once");
|
1726
1790
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1727
1791
|
};
|
1728
|
-
var __privateSet$
|
1729
|
-
__accessCheck$
|
1792
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
1793
|
+
__accessCheck$4(obj, member, "write to private field");
|
1730
1794
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1731
1795
|
return value;
|
1732
1796
|
};
|
1733
1797
|
var __privateMethod$3 = (obj, member, method) => {
|
1734
|
-
__accessCheck$
|
1798
|
+
__accessCheck$4(obj, member, "access private method");
|
1735
1799
|
return method;
|
1736
1800
|
};
|
1737
1801
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
1738
1802
|
const _Query = class _Query {
|
1739
1803
|
constructor(repository, table, data, rawParent) {
|
1740
|
-
__privateAdd$
|
1741
|
-
__privateAdd$
|
1742
|
-
__privateAdd$
|
1743
|
-
__privateAdd$
|
1804
|
+
__privateAdd$4(this, _cleanFilterConstraint);
|
1805
|
+
__privateAdd$4(this, _table$1, void 0);
|
1806
|
+
__privateAdd$4(this, _repository, void 0);
|
1807
|
+
__privateAdd$4(this, _data, { filter: {} });
|
1744
1808
|
// Implements pagination
|
1745
1809
|
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
1746
|
-
this.records = new
|
1747
|
-
__privateSet$
|
1810
|
+
this.records = new PageRecordArray(this, []);
|
1811
|
+
__privateSet$2(this, _table$1, table);
|
1748
1812
|
if (repository) {
|
1749
|
-
__privateSet$
|
1813
|
+
__privateSet$2(this, _repository, repository);
|
1750
1814
|
} else {
|
1751
|
-
__privateSet$
|
1815
|
+
__privateSet$2(this, _repository, this);
|
1752
1816
|
}
|
1753
1817
|
const parent = cleanParent(data, rawParent);
|
1754
|
-
__privateGet$
|
1755
|
-
__privateGet$
|
1756
|
-
__privateGet$
|
1757
|
-
__privateGet$
|
1758
|
-
__privateGet$
|
1759
|
-
__privateGet$
|
1760
|
-
__privateGet$
|
1761
|
-
__privateGet$
|
1762
|
-
__privateGet$
|
1763
|
-
__privateGet$
|
1764
|
-
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
1818
|
+
__privateGet$3(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
1819
|
+
__privateGet$3(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
|
1820
|
+
__privateGet$3(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
|
1821
|
+
__privateGet$3(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
|
1822
|
+
__privateGet$3(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
1823
|
+
__privateGet$3(this, _data).sort = data.sort ?? parent?.sort;
|
1824
|
+
__privateGet$3(this, _data).columns = data.columns ?? parent?.columns;
|
1825
|
+
__privateGet$3(this, _data).consistency = data.consistency ?? parent?.consistency;
|
1826
|
+
__privateGet$3(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1827
|
+
__privateGet$3(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
1765
1828
|
this.any = this.any.bind(this);
|
1766
1829
|
this.all = this.all.bind(this);
|
1767
1830
|
this.not = this.not.bind(this);
|
@@ -1772,10 +1835,10 @@ const _Query = class _Query {
|
|
1772
1835
|
Object.defineProperty(this, "repository", { enumerable: false });
|
1773
1836
|
}
|
1774
1837
|
getQueryOptions() {
|
1775
|
-
return __privateGet$
|
1838
|
+
return __privateGet$3(this, _data);
|
1776
1839
|
}
|
1777
1840
|
key() {
|
1778
|
-
const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$
|
1841
|
+
const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$3(this, _data);
|
1779
1842
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
1780
1843
|
return toBase64(key);
|
1781
1844
|
}
|
@@ -1786,7 +1849,7 @@ const _Query = class _Query {
|
|
1786
1849
|
*/
|
1787
1850
|
any(...queries) {
|
1788
1851
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1789
|
-
return new _Query(__privateGet$
|
1852
|
+
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $any } }, __privateGet$3(this, _data));
|
1790
1853
|
}
|
1791
1854
|
/**
|
1792
1855
|
* Builds a new query object representing a logical AND between the given subqueries.
|
@@ -1795,7 +1858,7 @@ const _Query = class _Query {
|
|
1795
1858
|
*/
|
1796
1859
|
all(...queries) {
|
1797
1860
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1798
|
-
return new _Query(__privateGet$
|
1861
|
+
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
|
1799
1862
|
}
|
1800
1863
|
/**
|
1801
1864
|
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
@@ -1804,7 +1867,7 @@ const _Query = class _Query {
|
|
1804
1867
|
*/
|
1805
1868
|
not(...queries) {
|
1806
1869
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1807
|
-
return new _Query(__privateGet$
|
1870
|
+
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $not } }, __privateGet$3(this, _data));
|
1808
1871
|
}
|
1809
1872
|
/**
|
1810
1873
|
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
@@ -1813,25 +1876,25 @@ const _Query = class _Query {
|
|
1813
1876
|
*/
|
1814
1877
|
none(...queries) {
|
1815
1878
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1816
|
-
return new _Query(__privateGet$
|
1879
|
+
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $none } }, __privateGet$3(this, _data));
|
1817
1880
|
}
|
1818
1881
|
filter(a, b) {
|
1819
1882
|
if (arguments.length === 1) {
|
1820
1883
|
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
1821
1884
|
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
1822
1885
|
}));
|
1823
|
-
const $all = compact([__privateGet$
|
1824
|
-
return new _Query(__privateGet$
|
1886
|
+
const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat(constraints));
|
1887
|
+
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
|
1825
1888
|
} else {
|
1826
1889
|
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
1827
|
-
const $all = compact([__privateGet$
|
1828
|
-
return new _Query(__privateGet$
|
1890
|
+
const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat(constraints));
|
1891
|
+
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
|
1829
1892
|
}
|
1830
1893
|
}
|
1831
1894
|
sort(column, direction = "asc") {
|
1832
|
-
const originalSort = [__privateGet$
|
1895
|
+
const originalSort = [__privateGet$3(this, _data).sort ?? []].flat();
|
1833
1896
|
const sort = [...originalSort, { column, direction }];
|
1834
|
-
return new _Query(__privateGet$
|
1897
|
+
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { sort }, __privateGet$3(this, _data));
|
1835
1898
|
}
|
1836
1899
|
/**
|
1837
1900
|
* Builds a new query specifying the set of columns to be returned in the query response.
|
@@ -1840,15 +1903,15 @@ const _Query = class _Query {
|
|
1840
1903
|
*/
|
1841
1904
|
select(columns) {
|
1842
1905
|
return new _Query(
|
1843
|
-
__privateGet$
|
1844
|
-
__privateGet$
|
1906
|
+
__privateGet$3(this, _repository),
|
1907
|
+
__privateGet$3(this, _table$1),
|
1845
1908
|
{ columns },
|
1846
|
-
__privateGet$
|
1909
|
+
__privateGet$3(this, _data)
|
1847
1910
|
);
|
1848
1911
|
}
|
1849
1912
|
getPaginated(options = {}) {
|
1850
|
-
const query = new _Query(__privateGet$
|
1851
|
-
return __privateGet$
|
1913
|
+
const query = new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), options, __privateGet$3(this, _data));
|
1914
|
+
return __privateGet$3(this, _repository).query(query);
|
1852
1915
|
}
|
1853
1916
|
/**
|
1854
1917
|
* Get results in an iterator
|
@@ -1885,7 +1948,7 @@ const _Query = class _Query {
|
|
1885
1948
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1886
1949
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1887
1950
|
}
|
1888
|
-
const array = new
|
1951
|
+
const array = new PageRecordArray(page, results.slice(0, size));
|
1889
1952
|
return array;
|
1890
1953
|
}
|
1891
1954
|
async getAll(options = {}) {
|
@@ -1894,7 +1957,7 @@ const _Query = class _Query {
|
|
1894
1957
|
for await (const page of this.getIterator({ ...rest, batchSize })) {
|
1895
1958
|
results.push(...page);
|
1896
1959
|
}
|
1897
|
-
return results;
|
1960
|
+
return new RecordArray(results);
|
1898
1961
|
}
|
1899
1962
|
async getFirst(options = {}) {
|
1900
1963
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
@@ -1909,20 +1972,12 @@ const _Query = class _Query {
|
|
1909
1972
|
async summarize(params = {}) {
|
1910
1973
|
const { summaries, summariesFilter, ...options } = params;
|
1911
1974
|
const query = new _Query(
|
1912
|
-
__privateGet$
|
1913
|
-
__privateGet$
|
1975
|
+
__privateGet$3(this, _repository),
|
1976
|
+
__privateGet$3(this, _table$1),
|
1914
1977
|
options,
|
1915
|
-
__privateGet$
|
1978
|
+
__privateGet$3(this, _data)
|
1916
1979
|
);
|
1917
|
-
return __privateGet$
|
1918
|
-
}
|
1919
|
-
/**
|
1920
|
-
* Builds a new query object adding a cache TTL in milliseconds.
|
1921
|
-
* @param ttl The cache TTL in milliseconds.
|
1922
|
-
* @returns A new Query object.
|
1923
|
-
*/
|
1924
|
-
cache(ttl) {
|
1925
|
-
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1980
|
+
return __privateGet$3(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
1926
1981
|
}
|
1927
1982
|
/**
|
1928
1983
|
* Retrieve next page of records
|
@@ -1968,7 +2023,7 @@ _repository = new WeakMap();
|
|
1968
2023
|
_data = new WeakMap();
|
1969
2024
|
_cleanFilterConstraint = new WeakSet();
|
1970
2025
|
cleanFilterConstraint_fn = function(column, value) {
|
1971
|
-
const columnType = __privateGet$
|
2026
|
+
const columnType = __privateGet$3(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
1972
2027
|
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
1973
2028
|
return { $includes: value };
|
1974
2029
|
}
|
@@ -1994,7 +2049,6 @@ const RecordColumnTypes = [
|
|
1994
2049
|
"email",
|
1995
2050
|
"multiple",
|
1996
2051
|
"link",
|
1997
|
-
"object",
|
1998
2052
|
"datetime",
|
1999
2053
|
"vector",
|
2000
2054
|
"file[]",
|
@@ -2002,12 +2056,7 @@ const RecordColumnTypes = [
|
|
2002
2056
|
"json"
|
2003
2057
|
];
|
2004
2058
|
function isIdentifiable(x) {
|
2005
|
-
return isObject(x) && isString(x?.
|
2006
|
-
}
|
2007
|
-
function isXataRecord(x) {
|
2008
|
-
const record = x;
|
2009
|
-
const metadata = record?.getMetadata();
|
2010
|
-
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
2059
|
+
return isObject(x) && isString(x?.xata_id);
|
2011
2060
|
}
|
2012
2061
|
|
2013
2062
|
function isValidExpandedColumn(column) {
|
@@ -2055,29 +2104,29 @@ function buildSortFilter(filter) {
|
|
2055
2104
|
}
|
2056
2105
|
}
|
2057
2106
|
|
2058
|
-
var __accessCheck$
|
2107
|
+
var __accessCheck$3 = (obj, member, msg) => {
|
2059
2108
|
if (!member.has(obj))
|
2060
2109
|
throw TypeError("Cannot " + msg);
|
2061
2110
|
};
|
2062
|
-
var __privateGet$
|
2063
|
-
__accessCheck$
|
2111
|
+
var __privateGet$2 = (obj, member, getter) => {
|
2112
|
+
__accessCheck$3(obj, member, "read from private field");
|
2064
2113
|
return getter ? getter.call(obj) : member.get(obj);
|
2065
2114
|
};
|
2066
|
-
var __privateAdd$
|
2115
|
+
var __privateAdd$3 = (obj, member, value) => {
|
2067
2116
|
if (member.has(obj))
|
2068
2117
|
throw TypeError("Cannot add the same private member more than once");
|
2069
2118
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
2070
2119
|
};
|
2071
|
-
var __privateSet$
|
2072
|
-
__accessCheck$
|
2120
|
+
var __privateSet$1 = (obj, member, value, setter) => {
|
2121
|
+
__accessCheck$3(obj, member, "write to private field");
|
2073
2122
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
2074
2123
|
return value;
|
2075
2124
|
};
|
2076
2125
|
var __privateMethod$2 = (obj, member, method) => {
|
2077
|
-
__accessCheck$
|
2126
|
+
__accessCheck$3(obj, member, "access private method");
|
2078
2127
|
return method;
|
2079
2128
|
};
|
2080
|
-
var _table, _getFetchProps, _db,
|
2129
|
+
var _table, _getFetchProps, _db, _schemaTables, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _getSchemaTables, getSchemaTables_fn, _transformObjectToApi, transformObjectToApi_fn;
|
2081
2130
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2082
2131
|
class Repository extends Query {
|
2083
2132
|
}
|
@@ -2088,41 +2137,37 @@ class RestRepository extends Query {
|
|
2088
2137
|
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
2089
2138
|
{}
|
2090
2139
|
);
|
2091
|
-
__privateAdd$
|
2092
|
-
__privateAdd$
|
2093
|
-
__privateAdd$
|
2094
|
-
__privateAdd$
|
2095
|
-
__privateAdd$
|
2096
|
-
__privateAdd$
|
2097
|
-
__privateAdd$
|
2098
|
-
__privateAdd$
|
2099
|
-
__privateAdd$
|
2100
|
-
__privateAdd$
|
2101
|
-
__privateAdd$
|
2102
|
-
__privateAdd$
|
2103
|
-
__privateAdd$
|
2104
|
-
__privateAdd$
|
2105
|
-
__privateAdd$
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
2109
|
-
__privateSet$
|
2110
|
-
__privateSet$4(this, _db, options.db);
|
2111
|
-
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2112
|
-
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2113
|
-
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2140
|
+
__privateAdd$3(this, _insertRecordWithoutId);
|
2141
|
+
__privateAdd$3(this, _insertRecordWithId);
|
2142
|
+
__privateAdd$3(this, _insertRecords);
|
2143
|
+
__privateAdd$3(this, _updateRecordWithID);
|
2144
|
+
__privateAdd$3(this, _updateRecords);
|
2145
|
+
__privateAdd$3(this, _upsertRecordWithID);
|
2146
|
+
__privateAdd$3(this, _deleteRecord);
|
2147
|
+
__privateAdd$3(this, _deleteRecords);
|
2148
|
+
__privateAdd$3(this, _getSchemaTables);
|
2149
|
+
__privateAdd$3(this, _transformObjectToApi);
|
2150
|
+
__privateAdd$3(this, _table, void 0);
|
2151
|
+
__privateAdd$3(this, _getFetchProps, void 0);
|
2152
|
+
__privateAdd$3(this, _db, void 0);
|
2153
|
+
__privateAdd$3(this, _schemaTables, void 0);
|
2154
|
+
__privateAdd$3(this, _trace, void 0);
|
2155
|
+
__privateSet$1(this, _table, options.table);
|
2156
|
+
__privateSet$1(this, _db, options.db);
|
2157
|
+
__privateSet$1(this, _schemaTables, options.schemaTables);
|
2158
|
+
__privateSet$1(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2114
2159
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2115
|
-
__privateSet$
|
2160
|
+
__privateSet$1(this, _trace, async (name, fn, options2 = {}) => {
|
2116
2161
|
return trace(name, fn, {
|
2117
2162
|
...options2,
|
2118
|
-
[TraceAttributes.TABLE]: __privateGet$
|
2163
|
+
[TraceAttributes.TABLE]: __privateGet$2(this, _table),
|
2119
2164
|
[TraceAttributes.KIND]: "sdk-operation",
|
2120
2165
|
[TraceAttributes.VERSION]: VERSION
|
2121
2166
|
});
|
2122
2167
|
});
|
2123
2168
|
}
|
2124
2169
|
async create(a, b, c, d) {
|
2125
|
-
return __privateGet$
|
2170
|
+
return __privateGet$2(this, _trace).call(this, "create", async () => {
|
2126
2171
|
const ifVersion = parseIfVersion(b, c, d);
|
2127
2172
|
if (Array.isArray(a)) {
|
2128
2173
|
if (a.length === 0)
|
@@ -2138,11 +2183,14 @@ class RestRepository extends Query {
|
|
2138
2183
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2139
2184
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2140
2185
|
}
|
2141
|
-
if (isObject(a) && isString(a.
|
2142
|
-
if (a.
|
2186
|
+
if (isObject(a) && isString(a.xata_id)) {
|
2187
|
+
if (a.xata_id === "")
|
2143
2188
|
throw new Error("The id can't be empty");
|
2144
2189
|
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2145
|
-
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.
|
2190
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
|
2191
|
+
createOnly: true,
|
2192
|
+
ifVersion
|
2193
|
+
});
|
2146
2194
|
}
|
2147
2195
|
if (isObject(a)) {
|
2148
2196
|
const columns = isValidSelectableColumns(b) ? b : void 0;
|
@@ -2152,15 +2200,15 @@ class RestRepository extends Query {
|
|
2152
2200
|
});
|
2153
2201
|
}
|
2154
2202
|
async read(a, b) {
|
2155
|
-
return __privateGet$
|
2203
|
+
return __privateGet$2(this, _trace).call(this, "read", async () => {
|
2156
2204
|
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2157
2205
|
if (Array.isArray(a)) {
|
2158
2206
|
if (a.length === 0)
|
2159
2207
|
return [];
|
2160
2208
|
const ids = a.map((item) => extractId(item));
|
2161
|
-
const finalObjects = await this.getAll({ filter: {
|
2209
|
+
const finalObjects = await this.getAll({ filter: { xata_id: { $any: compact(ids) } }, columns });
|
2162
2210
|
const dictionary = finalObjects.reduce((acc, object) => {
|
2163
|
-
acc[object.
|
2211
|
+
acc[object.xata_id] = object;
|
2164
2212
|
return acc;
|
2165
2213
|
}, {});
|
2166
2214
|
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
@@ -2173,17 +2221,17 @@ class RestRepository extends Query {
|
|
2173
2221
|
workspace: "{workspaceId}",
|
2174
2222
|
dbBranchName: "{dbBranch}",
|
2175
2223
|
region: "{region}",
|
2176
|
-
tableName: __privateGet$
|
2224
|
+
tableName: __privateGet$2(this, _table),
|
2177
2225
|
recordId: id
|
2178
2226
|
},
|
2179
2227
|
queryParams: { columns },
|
2180
|
-
...__privateGet$
|
2228
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2181
2229
|
});
|
2182
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
2230
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2183
2231
|
return initObject(
|
2184
|
-
__privateGet$
|
2232
|
+
__privateGet$2(this, _db),
|
2185
2233
|
schemaTables,
|
2186
|
-
__privateGet$
|
2234
|
+
__privateGet$2(this, _table),
|
2187
2235
|
response,
|
2188
2236
|
columns
|
2189
2237
|
);
|
@@ -2198,7 +2246,7 @@ class RestRepository extends Query {
|
|
2198
2246
|
});
|
2199
2247
|
}
|
2200
2248
|
async readOrThrow(a, b) {
|
2201
|
-
return __privateGet$
|
2249
|
+
return __privateGet$2(this, _trace).call(this, "readOrThrow", async () => {
|
2202
2250
|
const result = await this.read(a, b);
|
2203
2251
|
if (Array.isArray(result)) {
|
2204
2252
|
const missingIds = compact(
|
@@ -2217,12 +2265,12 @@ class RestRepository extends Query {
|
|
2217
2265
|
});
|
2218
2266
|
}
|
2219
2267
|
async update(a, b, c, d) {
|
2220
|
-
return __privateGet$
|
2268
|
+
return __privateGet$2(this, _trace).call(this, "update", async () => {
|
2221
2269
|
const ifVersion = parseIfVersion(b, c, d);
|
2222
2270
|
if (Array.isArray(a)) {
|
2223
2271
|
if (a.length === 0)
|
2224
2272
|
return [];
|
2225
|
-
const existing = await this.read(a, ["
|
2273
|
+
const existing = await this.read(a, ["xata_id"]);
|
2226
2274
|
const updates = a.filter((_item, index) => existing[index] !== null);
|
2227
2275
|
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
|
2228
2276
|
ifVersion,
|
@@ -2237,9 +2285,9 @@ class RestRepository extends Query {
|
|
2237
2285
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2238
2286
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2239
2287
|
}
|
2240
|
-
if (isObject(a) && isString(a.
|
2288
|
+
if (isObject(a) && isString(a.xata_id)) {
|
2241
2289
|
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2242
|
-
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.
|
2290
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
|
2243
2291
|
}
|
2244
2292
|
} catch (error) {
|
2245
2293
|
if (error.status === 422)
|
@@ -2250,7 +2298,7 @@ class RestRepository extends Query {
|
|
2250
2298
|
});
|
2251
2299
|
}
|
2252
2300
|
async updateOrThrow(a, b, c, d) {
|
2253
|
-
return __privateGet$
|
2301
|
+
return __privateGet$2(this, _trace).call(this, "updateOrThrow", async () => {
|
2254
2302
|
const result = await this.update(a, b, c, d);
|
2255
2303
|
if (Array.isArray(result)) {
|
2256
2304
|
const missingIds = compact(
|
@@ -2269,7 +2317,7 @@ class RestRepository extends Query {
|
|
2269
2317
|
});
|
2270
2318
|
}
|
2271
2319
|
async createOrUpdate(a, b, c, d) {
|
2272
|
-
return __privateGet$
|
2320
|
+
return __privateGet$2(this, _trace).call(this, "createOrUpdate", async () => {
|
2273
2321
|
const ifVersion = parseIfVersion(b, c, d);
|
2274
2322
|
if (Array.isArray(a)) {
|
2275
2323
|
if (a.length === 0)
|
@@ -2288,23 +2336,23 @@ class RestRepository extends Query {
|
|
2288
2336
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2289
2337
|
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2290
2338
|
}
|
2291
|
-
if (isObject(a) && isString(a.
|
2292
|
-
if (a.
|
2339
|
+
if (isObject(a) && isString(a.xata_id)) {
|
2340
|
+
if (a.xata_id === "")
|
2293
2341
|
throw new Error("The id can't be empty");
|
2294
2342
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2295
|
-
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.
|
2343
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
|
2296
2344
|
}
|
2297
2345
|
if (!isDefined(a) && isObject(b)) {
|
2298
2346
|
return await this.create(b, c);
|
2299
2347
|
}
|
2300
|
-
if (isObject(a) && !isDefined(a.
|
2348
|
+
if (isObject(a) && !isDefined(a.xata_id)) {
|
2301
2349
|
return await this.create(a, b);
|
2302
2350
|
}
|
2303
2351
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2304
2352
|
});
|
2305
2353
|
}
|
2306
2354
|
async createOrReplace(a, b, c, d) {
|
2307
|
-
return __privateGet$
|
2355
|
+
return __privateGet$2(this, _trace).call(this, "createOrReplace", async () => {
|
2308
2356
|
const ifVersion = parseIfVersion(b, c, d);
|
2309
2357
|
if (Array.isArray(a)) {
|
2310
2358
|
if (a.length === 0)
|
@@ -2320,31 +2368,34 @@ class RestRepository extends Query {
|
|
2320
2368
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2321
2369
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2322
2370
|
}
|
2323
|
-
if (isObject(a) && isString(a.
|
2324
|
-
if (a.
|
2371
|
+
if (isObject(a) && isString(a.xata_id)) {
|
2372
|
+
if (a.xata_id === "")
|
2325
2373
|
throw new Error("The id can't be empty");
|
2326
2374
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2327
|
-
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.
|
2375
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
|
2376
|
+
createOnly: false,
|
2377
|
+
ifVersion
|
2378
|
+
});
|
2328
2379
|
}
|
2329
2380
|
if (!isDefined(a) && isObject(b)) {
|
2330
2381
|
return await this.create(b, c);
|
2331
2382
|
}
|
2332
|
-
if (isObject(a) && !isDefined(a.
|
2383
|
+
if (isObject(a) && !isDefined(a.xata_id)) {
|
2333
2384
|
return await this.create(a, b);
|
2334
2385
|
}
|
2335
2386
|
throw new Error("Invalid arguments for createOrReplace method");
|
2336
2387
|
});
|
2337
2388
|
}
|
2338
2389
|
async delete(a, b) {
|
2339
|
-
return __privateGet$
|
2390
|
+
return __privateGet$2(this, _trace).call(this, "delete", async () => {
|
2340
2391
|
if (Array.isArray(a)) {
|
2341
2392
|
if (a.length === 0)
|
2342
2393
|
return [];
|
2343
2394
|
const ids = a.map((o) => {
|
2344
2395
|
if (isString(o))
|
2345
2396
|
return o;
|
2346
|
-
if (isString(o.
|
2347
|
-
return o.
|
2397
|
+
if (isString(o.xata_id))
|
2398
|
+
return o.xata_id;
|
2348
2399
|
throw new Error("Invalid arguments for delete method");
|
2349
2400
|
});
|
2350
2401
|
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
@@ -2355,14 +2406,14 @@ class RestRepository extends Query {
|
|
2355
2406
|
if (isString(a)) {
|
2356
2407
|
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
2357
2408
|
}
|
2358
|
-
if (isObject(a) && isString(a.
|
2359
|
-
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.
|
2409
|
+
if (isObject(a) && isString(a.xata_id)) {
|
2410
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.xata_id, b);
|
2360
2411
|
}
|
2361
2412
|
throw new Error("Invalid arguments for delete method");
|
2362
2413
|
});
|
2363
2414
|
}
|
2364
2415
|
async deleteOrThrow(a, b) {
|
2365
|
-
return __privateGet$
|
2416
|
+
return __privateGet$2(this, _trace).call(this, "deleteOrThrow", async () => {
|
2366
2417
|
const result = await this.delete(a, b);
|
2367
2418
|
if (Array.isArray(result)) {
|
2368
2419
|
const missingIds = compact(
|
@@ -2380,13 +2431,13 @@ class RestRepository extends Query {
|
|
2380
2431
|
});
|
2381
2432
|
}
|
2382
2433
|
async search(query, options = {}) {
|
2383
|
-
return __privateGet$
|
2434
|
+
return __privateGet$2(this, _trace).call(this, "search", async () => {
|
2384
2435
|
const { records, totalCount } = await searchTable({
|
2385
2436
|
pathParams: {
|
2386
2437
|
workspace: "{workspaceId}",
|
2387
2438
|
dbBranchName: "{dbBranch}",
|
2388
2439
|
region: "{region}",
|
2389
|
-
tableName: __privateGet$
|
2440
|
+
tableName: __privateGet$2(this, _table)
|
2390
2441
|
},
|
2391
2442
|
body: {
|
2392
2443
|
query,
|
@@ -2398,23 +2449,23 @@ class RestRepository extends Query {
|
|
2398
2449
|
page: options.page,
|
2399
2450
|
target: options.target
|
2400
2451
|
},
|
2401
|
-
...__privateGet$
|
2452
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2402
2453
|
});
|
2403
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
2454
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2404
2455
|
return {
|
2405
|
-
records: records.map((item) => initObject(__privateGet$
|
2456
|
+
records: records.map((item) => initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), item, ["*"])),
|
2406
2457
|
totalCount
|
2407
2458
|
};
|
2408
2459
|
});
|
2409
2460
|
}
|
2410
2461
|
async vectorSearch(column, query, options) {
|
2411
|
-
return __privateGet$
|
2462
|
+
return __privateGet$2(this, _trace).call(this, "vectorSearch", async () => {
|
2412
2463
|
const { records, totalCount } = await vectorSearchTable({
|
2413
2464
|
pathParams: {
|
2414
2465
|
workspace: "{workspaceId}",
|
2415
2466
|
dbBranchName: "{dbBranch}",
|
2416
2467
|
region: "{region}",
|
2417
|
-
tableName: __privateGet$
|
2468
|
+
tableName: __privateGet$2(this, _table)
|
2418
2469
|
},
|
2419
2470
|
body: {
|
2420
2471
|
column,
|
@@ -2423,42 +2474,39 @@ class RestRepository extends Query {
|
|
2423
2474
|
size: options?.size,
|
2424
2475
|
filter: options?.filter
|
2425
2476
|
},
|
2426
|
-
...__privateGet$
|
2477
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2427
2478
|
});
|
2428
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
2479
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2429
2480
|
return {
|
2430
|
-
records: records.map((item) => initObject(__privateGet$
|
2481
|
+
records: records.map((item) => initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), item, ["*"])),
|
2431
2482
|
totalCount
|
2432
2483
|
};
|
2433
2484
|
});
|
2434
2485
|
}
|
2435
2486
|
async aggregate(aggs, filter) {
|
2436
|
-
return __privateGet$
|
2487
|
+
return __privateGet$2(this, _trace).call(this, "aggregate", async () => {
|
2437
2488
|
const result = await aggregateTable({
|
2438
2489
|
pathParams: {
|
2439
2490
|
workspace: "{workspaceId}",
|
2440
2491
|
dbBranchName: "{dbBranch}",
|
2441
2492
|
region: "{region}",
|
2442
|
-
tableName: __privateGet$
|
2493
|
+
tableName: __privateGet$2(this, _table)
|
2443
2494
|
},
|
2444
2495
|
body: { aggs, filter },
|
2445
|
-
...__privateGet$
|
2496
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2446
2497
|
});
|
2447
2498
|
return result;
|
2448
2499
|
});
|
2449
2500
|
}
|
2450
2501
|
async query(query) {
|
2451
|
-
return __privateGet$
|
2452
|
-
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
2453
|
-
if (cacheQuery)
|
2454
|
-
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2502
|
+
return __privateGet$2(this, _trace).call(this, "query", async () => {
|
2455
2503
|
const data = query.getQueryOptions();
|
2456
2504
|
const { meta, records: objects } = await queryTable({
|
2457
2505
|
pathParams: {
|
2458
2506
|
workspace: "{workspaceId}",
|
2459
2507
|
dbBranchName: "{dbBranch}",
|
2460
2508
|
region: "{region}",
|
2461
|
-
tableName: __privateGet$
|
2509
|
+
tableName: __privateGet$2(this, _table)
|
2462
2510
|
},
|
2463
2511
|
body: {
|
2464
2512
|
filter: cleanFilter(data.filter),
|
@@ -2468,31 +2516,30 @@ class RestRepository extends Query {
|
|
2468
2516
|
consistency: data.consistency
|
2469
2517
|
},
|
2470
2518
|
fetchOptions: data.fetchOptions,
|
2471
|
-
...__privateGet$
|
2519
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2472
2520
|
});
|
2473
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
2521
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2474
2522
|
const records = objects.map(
|
2475
2523
|
(record) => initObject(
|
2476
|
-
__privateGet$
|
2524
|
+
__privateGet$2(this, _db),
|
2477
2525
|
schemaTables,
|
2478
|
-
__privateGet$
|
2526
|
+
__privateGet$2(this, _table),
|
2479
2527
|
record,
|
2480
2528
|
data.columns ?? ["*"]
|
2481
2529
|
)
|
2482
2530
|
);
|
2483
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
2484
2531
|
return new Page(query, meta, records);
|
2485
2532
|
});
|
2486
2533
|
}
|
2487
2534
|
async summarizeTable(query, summaries, summariesFilter) {
|
2488
|
-
return __privateGet$
|
2535
|
+
return __privateGet$2(this, _trace).call(this, "summarize", async () => {
|
2489
2536
|
const data = query.getQueryOptions();
|
2490
2537
|
const result = await summarizeTable({
|
2491
2538
|
pathParams: {
|
2492
2539
|
workspace: "{workspaceId}",
|
2493
2540
|
dbBranchName: "{dbBranch}",
|
2494
2541
|
region: "{region}",
|
2495
|
-
tableName: __privateGet$
|
2542
|
+
tableName: __privateGet$2(this, _table)
|
2496
2543
|
},
|
2497
2544
|
body: {
|
2498
2545
|
filter: cleanFilter(data.filter),
|
@@ -2503,13 +2550,13 @@ class RestRepository extends Query {
|
|
2503
2550
|
summaries,
|
2504
2551
|
summariesFilter
|
2505
2552
|
},
|
2506
|
-
...__privateGet$
|
2553
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2507
2554
|
});
|
2508
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
2555
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2509
2556
|
return {
|
2510
2557
|
...result,
|
2511
2558
|
summaries: result.summaries.map(
|
2512
|
-
(summary) => initObject(__privateGet$
|
2559
|
+
(summary) => initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), summary, data.columns ?? [])
|
2513
2560
|
)
|
2514
2561
|
};
|
2515
2562
|
});
|
@@ -2521,7 +2568,7 @@ class RestRepository extends Query {
|
|
2521
2568
|
workspace: "{workspaceId}",
|
2522
2569
|
dbBranchName: "{dbBranch}",
|
2523
2570
|
region: "{region}",
|
2524
|
-
tableName: __privateGet$
|
2571
|
+
tableName: __privateGet$2(this, _table),
|
2525
2572
|
sessionId: options?.sessionId
|
2526
2573
|
},
|
2527
2574
|
body: {
|
@@ -2531,7 +2578,7 @@ class RestRepository extends Query {
|
|
2531
2578
|
search: options?.searchType === "keyword" ? options?.search : void 0,
|
2532
2579
|
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
2533
2580
|
},
|
2534
|
-
...__privateGet$
|
2581
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2535
2582
|
};
|
2536
2583
|
if (options?.onMessage) {
|
2537
2584
|
fetchSSERequest({
|
@@ -2551,25 +2598,25 @@ class RestRepository extends Query {
|
|
2551
2598
|
_table = new WeakMap();
|
2552
2599
|
_getFetchProps = new WeakMap();
|
2553
2600
|
_db = new WeakMap();
|
2554
|
-
|
2555
|
-
_schemaTables$2 = new WeakMap();
|
2601
|
+
_schemaTables = new WeakMap();
|
2556
2602
|
_trace = new WeakMap();
|
2557
2603
|
_insertRecordWithoutId = new WeakSet();
|
2558
2604
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2559
2605
|
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2606
|
+
console.log("record", record);
|
2560
2607
|
const response = await insertRecord({
|
2561
2608
|
pathParams: {
|
2562
2609
|
workspace: "{workspaceId}",
|
2563
2610
|
dbBranchName: "{dbBranch}",
|
2564
2611
|
region: "{region}",
|
2565
|
-
tableName: __privateGet$
|
2612
|
+
tableName: __privateGet$2(this, _table)
|
2566
2613
|
},
|
2567
2614
|
queryParams: { columns },
|
2568
2615
|
body: record,
|
2569
|
-
...__privateGet$
|
2616
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2570
2617
|
});
|
2571
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
2572
|
-
return initObject(__privateGet$
|
2618
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2619
|
+
return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
|
2573
2620
|
};
|
2574
2621
|
_insertRecordWithId = new WeakSet();
|
2575
2622
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
@@ -2581,21 +2628,21 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2581
2628
|
workspace: "{workspaceId}",
|
2582
2629
|
dbBranchName: "{dbBranch}",
|
2583
2630
|
region: "{region}",
|
2584
|
-
tableName: __privateGet$
|
2631
|
+
tableName: __privateGet$2(this, _table),
|
2585
2632
|
recordId
|
2586
2633
|
},
|
2587
2634
|
body: record,
|
2588
2635
|
queryParams: { createOnly, columns, ifVersion },
|
2589
|
-
...__privateGet$
|
2636
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2590
2637
|
});
|
2591
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
2592
|
-
return initObject(__privateGet$
|
2638
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2639
|
+
return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
|
2593
2640
|
};
|
2594
2641
|
_insertRecords = new WeakSet();
|
2595
2642
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2596
2643
|
const operations = await promiseMap(objects, async (object) => {
|
2597
2644
|
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2598
|
-
return { insert: { table: __privateGet$
|
2645
|
+
return { insert: { table: __privateGet$2(this, _table), record, createOnly, ifVersion } };
|
2599
2646
|
});
|
2600
2647
|
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2601
2648
|
const ids = [];
|
@@ -2607,7 +2654,7 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2607
2654
|
region: "{region}"
|
2608
2655
|
},
|
2609
2656
|
body: { operations: operations2 },
|
2610
|
-
...__privateGet$
|
2657
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2611
2658
|
});
|
2612
2659
|
for (const result of results) {
|
2613
2660
|
if (result.operation === "insert") {
|
@@ -2623,22 +2670,22 @@ _updateRecordWithID = new WeakSet();
|
|
2623
2670
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2624
2671
|
if (!recordId)
|
2625
2672
|
return null;
|
2626
|
-
const {
|
2673
|
+
const { xata_id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2627
2674
|
try {
|
2628
2675
|
const response = await updateRecordWithID({
|
2629
2676
|
pathParams: {
|
2630
2677
|
workspace: "{workspaceId}",
|
2631
2678
|
dbBranchName: "{dbBranch}",
|
2632
2679
|
region: "{region}",
|
2633
|
-
tableName: __privateGet$
|
2680
|
+
tableName: __privateGet$2(this, _table),
|
2634
2681
|
recordId
|
2635
2682
|
},
|
2636
2683
|
queryParams: { columns, ifVersion },
|
2637
2684
|
body: record,
|
2638
|
-
...__privateGet$
|
2685
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2639
2686
|
});
|
2640
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
2641
|
-
return initObject(__privateGet$
|
2687
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2688
|
+
return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
|
2642
2689
|
} catch (e) {
|
2643
2690
|
if (isObject(e) && e.status === 404) {
|
2644
2691
|
return null;
|
@@ -2648,9 +2695,9 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2648
2695
|
};
|
2649
2696
|
_updateRecords = new WeakSet();
|
2650
2697
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2651
|
-
const operations = await promiseMap(objects, async ({
|
2698
|
+
const operations = await promiseMap(objects, async ({ xata_id, ...object }) => {
|
2652
2699
|
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2653
|
-
return { update: { table: __privateGet$
|
2700
|
+
return { update: { table: __privateGet$2(this, _table), id: xata_id, ifVersion, upsert, fields } };
|
2654
2701
|
});
|
2655
2702
|
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2656
2703
|
const ids = [];
|
@@ -2662,7 +2709,7 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2662
2709
|
region: "{region}"
|
2663
2710
|
},
|
2664
2711
|
body: { operations: operations2 },
|
2665
|
-
...__privateGet$
|
2712
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2666
2713
|
});
|
2667
2714
|
for (const result of results) {
|
2668
2715
|
if (result.operation === "update") {
|
@@ -2683,15 +2730,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2683
2730
|
workspace: "{workspaceId}",
|
2684
2731
|
dbBranchName: "{dbBranch}",
|
2685
2732
|
region: "{region}",
|
2686
|
-
tableName: __privateGet$
|
2733
|
+
tableName: __privateGet$2(this, _table),
|
2687
2734
|
recordId
|
2688
2735
|
},
|
2689
2736
|
queryParams: { columns, ifVersion },
|
2690
2737
|
body: object,
|
2691
|
-
...__privateGet$
|
2738
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2692
2739
|
});
|
2693
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
2694
|
-
return initObject(__privateGet$
|
2740
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2741
|
+
return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
|
2695
2742
|
};
|
2696
2743
|
_deleteRecord = new WeakSet();
|
2697
2744
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
@@ -2703,14 +2750,14 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2703
2750
|
workspace: "{workspaceId}",
|
2704
2751
|
dbBranchName: "{dbBranch}",
|
2705
2752
|
region: "{region}",
|
2706
|
-
tableName: __privateGet$
|
2753
|
+
tableName: __privateGet$2(this, _table),
|
2707
2754
|
recordId
|
2708
2755
|
},
|
2709
2756
|
queryParams: { columns },
|
2710
|
-
...__privateGet$
|
2757
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2711
2758
|
});
|
2712
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
2713
|
-
return initObject(__privateGet$
|
2759
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2760
|
+
return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
|
2714
2761
|
} catch (e) {
|
2715
2762
|
if (isObject(e) && e.status === 404) {
|
2716
2763
|
return null;
|
@@ -2721,7 +2768,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2721
2768
|
_deleteRecords = new WeakSet();
|
2722
2769
|
deleteRecords_fn = async function(recordIds) {
|
2723
2770
|
const chunkedOperations = chunk(
|
2724
|
-
compact(recordIds).map((id) => ({ delete: { table: __privateGet$
|
2771
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$2(this, _table), id } })),
|
2725
2772
|
BULK_OPERATION_MAX_SIZE
|
2726
2773
|
);
|
2727
2774
|
for (const operations of chunkedOperations) {
|
@@ -2732,52 +2779,35 @@ deleteRecords_fn = async function(recordIds) {
|
|
2732
2779
|
region: "{region}"
|
2733
2780
|
},
|
2734
2781
|
body: { operations },
|
2735
|
-
...__privateGet$
|
2782
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2736
2783
|
});
|
2737
2784
|
}
|
2738
2785
|
};
|
2739
|
-
|
2740
|
-
|
2741
|
-
|
2742
|
-
|
2743
|
-
_getCacheQuery = new WeakSet();
|
2744
|
-
getCacheQuery_fn = async function(query) {
|
2745
|
-
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2746
|
-
const result = await __privateGet$4(this, _cache)?.get(key);
|
2747
|
-
if (!result)
|
2748
|
-
return null;
|
2749
|
-
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
2750
|
-
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2751
|
-
if (ttl < 0)
|
2752
|
-
return null;
|
2753
|
-
const hasExpired = result.date.getTime() + ttl < Date.now();
|
2754
|
-
return hasExpired ? null : result;
|
2755
|
-
};
|
2756
|
-
_getSchemaTables$1 = new WeakSet();
|
2757
|
-
getSchemaTables_fn$1 = async function() {
|
2758
|
-
if (__privateGet$4(this, _schemaTables$2))
|
2759
|
-
return __privateGet$4(this, _schemaTables$2);
|
2786
|
+
_getSchemaTables = new WeakSet();
|
2787
|
+
getSchemaTables_fn = async function() {
|
2788
|
+
if (__privateGet$2(this, _schemaTables))
|
2789
|
+
return __privateGet$2(this, _schemaTables);
|
2760
2790
|
const { schema } = await getBranchDetails({
|
2761
2791
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2762
|
-
...__privateGet$
|
2792
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2763
2793
|
});
|
2764
|
-
__privateSet$
|
2794
|
+
__privateSet$1(this, _schemaTables, schema.tables);
|
2765
2795
|
return schema.tables;
|
2766
2796
|
};
|
2767
2797
|
_transformObjectToApi = new WeakSet();
|
2768
2798
|
transformObjectToApi_fn = async function(object) {
|
2769
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
2770
|
-
const schema = schemaTables.find((table) => table.name === __privateGet$
|
2799
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2800
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$2(this, _table));
|
2771
2801
|
if (!schema)
|
2772
|
-
throw new Error(`Table ${__privateGet$
|
2802
|
+
throw new Error(`Table ${__privateGet$2(this, _table)} not found in schema`);
|
2773
2803
|
const result = {};
|
2774
2804
|
for (const [key, value] of Object.entries(object)) {
|
2775
|
-
if (
|
2805
|
+
if (["xata_version", "xata_createdat", "xata_updatedat"].includes(key))
|
2776
2806
|
continue;
|
2777
2807
|
const type = schema.columns.find((column) => column.name === key)?.type;
|
2778
2808
|
switch (type) {
|
2779
2809
|
case "link": {
|
2780
|
-
result[key] = isIdentifiable(value) ? value.
|
2810
|
+
result[key] = isIdentifiable(value) ? value.xata_id : value;
|
2781
2811
|
break;
|
2782
2812
|
}
|
2783
2813
|
case "datetime": {
|
@@ -2801,8 +2831,7 @@ transformObjectToApi_fn = async function(object) {
|
|
2801
2831
|
};
|
2802
2832
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2803
2833
|
const data = {};
|
2804
|
-
|
2805
|
-
Object.assign(data, rest);
|
2834
|
+
Object.assign(data, { ...object });
|
2806
2835
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2807
2836
|
if (!columns)
|
2808
2837
|
console.error(`Table ${table} not found in schema`);
|
@@ -2865,28 +2894,21 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2865
2894
|
}
|
2866
2895
|
}
|
2867
2896
|
const record = { ...data };
|
2868
|
-
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
2869
2897
|
record.read = function(columns2) {
|
2870
|
-
return db[table].read(record["
|
2898
|
+
return db[table].read(record["xata_id"], columns2);
|
2871
2899
|
};
|
2872
2900
|
record.update = function(data2, b, c) {
|
2873
2901
|
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2874
2902
|
const ifVersion = parseIfVersion(b, c);
|
2875
|
-
return db[table].update(record["
|
2903
|
+
return db[table].update(record["xata_id"], data2, columns2, { ifVersion });
|
2876
2904
|
};
|
2877
2905
|
record.replace = function(data2, b, c) {
|
2878
2906
|
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2879
2907
|
const ifVersion = parseIfVersion(b, c);
|
2880
|
-
return db[table].createOrReplace(record["
|
2908
|
+
return db[table].createOrReplace(record["xata_id"], data2, columns2, { ifVersion });
|
2881
2909
|
};
|
2882
2910
|
record.delete = function() {
|
2883
|
-
return db[table].delete(record["
|
2884
|
-
};
|
2885
|
-
if (metadata !== void 0) {
|
2886
|
-
record.xata = Object.freeze(metadata);
|
2887
|
-
}
|
2888
|
-
record.getMetadata = function() {
|
2889
|
-
return record.xata;
|
2911
|
+
return db[table].delete(record["xata_id"]);
|
2890
2912
|
};
|
2891
2913
|
record.toSerializable = function() {
|
2892
2914
|
return JSON.parse(JSON.stringify(record));
|
@@ -2894,7 +2916,7 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2894
2916
|
record.toString = function() {
|
2895
2917
|
return JSON.stringify(record);
|
2896
2918
|
};
|
2897
|
-
for (const prop of ["read", "update", "replace", "delete", "
|
2919
|
+
for (const prop of ["read", "update", "replace", "delete", "toSerializable", "toString"]) {
|
2898
2920
|
Object.defineProperty(record, prop, { enumerable: false });
|
2899
2921
|
}
|
2900
2922
|
Object.freeze(record);
|
@@ -2903,8 +2925,8 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2903
2925
|
function extractId(value) {
|
2904
2926
|
if (isString(value))
|
2905
2927
|
return value;
|
2906
|
-
if (isObject(value) && isString(value.
|
2907
|
-
return value.
|
2928
|
+
if (isObject(value) && isString(value.xata_id))
|
2929
|
+
return value.xata_id;
|
2908
2930
|
return void 0;
|
2909
2931
|
}
|
2910
2932
|
function isValidColumn(columns, column) {
|
@@ -2921,55 +2943,6 @@ function parseIfVersion(...args) {
|
|
2921
2943
|
return void 0;
|
2922
2944
|
}
|
2923
2945
|
|
2924
|
-
var __accessCheck$3 = (obj, member, msg) => {
|
2925
|
-
if (!member.has(obj))
|
2926
|
-
throw TypeError("Cannot " + msg);
|
2927
|
-
};
|
2928
|
-
var __privateGet$3 = (obj, member, getter) => {
|
2929
|
-
__accessCheck$3(obj, member, "read from private field");
|
2930
|
-
return getter ? getter.call(obj) : member.get(obj);
|
2931
|
-
};
|
2932
|
-
var __privateAdd$3 = (obj, member, value) => {
|
2933
|
-
if (member.has(obj))
|
2934
|
-
throw TypeError("Cannot add the same private member more than once");
|
2935
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
2936
|
-
};
|
2937
|
-
var __privateSet$3 = (obj, member, value, setter) => {
|
2938
|
-
__accessCheck$3(obj, member, "write to private field");
|
2939
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
2940
|
-
return value;
|
2941
|
-
};
|
2942
|
-
var _map;
|
2943
|
-
class SimpleCache {
|
2944
|
-
constructor(options = {}) {
|
2945
|
-
__privateAdd$3(this, _map, void 0);
|
2946
|
-
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
2947
|
-
this.capacity = options.max ?? 500;
|
2948
|
-
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
2949
|
-
}
|
2950
|
-
async getAll() {
|
2951
|
-
return Object.fromEntries(__privateGet$3(this, _map));
|
2952
|
-
}
|
2953
|
-
async get(key) {
|
2954
|
-
return __privateGet$3(this, _map).get(key) ?? null;
|
2955
|
-
}
|
2956
|
-
async set(key, value) {
|
2957
|
-
await this.delete(key);
|
2958
|
-
__privateGet$3(this, _map).set(key, value);
|
2959
|
-
if (__privateGet$3(this, _map).size > this.capacity) {
|
2960
|
-
const leastRecentlyUsed = __privateGet$3(this, _map).keys().next().value;
|
2961
|
-
await this.delete(leastRecentlyUsed);
|
2962
|
-
}
|
2963
|
-
}
|
2964
|
-
async delete(key) {
|
2965
|
-
__privateGet$3(this, _map).delete(key);
|
2966
|
-
}
|
2967
|
-
async clear() {
|
2968
|
-
return __privateGet$3(this, _map).clear();
|
2969
|
-
}
|
2970
|
-
}
|
2971
|
-
_map = new WeakMap();
|
2972
|
-
|
2973
2946
|
const greaterThan = (value) => ({ $gt: value });
|
2974
2947
|
const gt = greaterThan;
|
2975
2948
|
const greaterThanEquals = (value) => ({ $ge: value });
|
@@ -3002,7 +2975,7 @@ var __accessCheck$2 = (obj, member, msg) => {
|
|
3002
2975
|
if (!member.has(obj))
|
3003
2976
|
throw TypeError("Cannot " + msg);
|
3004
2977
|
};
|
3005
|
-
var __privateGet$
|
2978
|
+
var __privateGet$1 = (obj, member, getter) => {
|
3006
2979
|
__accessCheck$2(obj, member, "read from private field");
|
3007
2980
|
return getter ? getter.call(obj) : member.get(obj);
|
3008
2981
|
};
|
@@ -3011,18 +2984,11 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
3011
2984
|
throw TypeError("Cannot add the same private member more than once");
|
3012
2985
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
3013
2986
|
};
|
3014
|
-
var
|
3015
|
-
__accessCheck$2(obj, member, "write to private field");
|
3016
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
3017
|
-
return value;
|
3018
|
-
};
|
3019
|
-
var _tables, _schemaTables$1;
|
2987
|
+
var _tables;
|
3020
2988
|
class SchemaPlugin extends XataPlugin {
|
3021
|
-
constructor(
|
2989
|
+
constructor() {
|
3022
2990
|
super();
|
3023
2991
|
__privateAdd$2(this, _tables, {});
|
3024
|
-
__privateAdd$2(this, _schemaTables$1, void 0);
|
3025
|
-
__privateSet$2(this, _schemaTables$1, schemaTables);
|
3026
2992
|
}
|
3027
2993
|
build(pluginOptions) {
|
3028
2994
|
const db = new Proxy(
|
@@ -3031,22 +2997,21 @@ class SchemaPlugin extends XataPlugin {
|
|
3031
2997
|
get: (_target, table) => {
|
3032
2998
|
if (!isString(table))
|
3033
2999
|
throw new Error("Invalid table name");
|
3034
|
-
if (__privateGet$
|
3035
|
-
__privateGet$
|
3000
|
+
if (__privateGet$1(this, _tables)[table] === void 0) {
|
3001
|
+
__privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: pluginOptions.tables });
|
3036
3002
|
}
|
3037
|
-
return __privateGet$
|
3003
|
+
return __privateGet$1(this, _tables)[table];
|
3038
3004
|
}
|
3039
3005
|
}
|
3040
3006
|
);
|
3041
|
-
const tableNames =
|
3007
|
+
const tableNames = pluginOptions.tables?.map(({ name }) => name) ?? [];
|
3042
3008
|
for (const table of tableNames) {
|
3043
|
-
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables:
|
3009
|
+
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: pluginOptions.tables });
|
3044
3010
|
}
|
3045
3011
|
return db;
|
3046
3012
|
}
|
3047
3013
|
}
|
3048
3014
|
_tables = new WeakMap();
|
3049
|
-
_schemaTables$1 = new WeakMap();
|
3050
3015
|
|
3051
3016
|
class FilesPlugin extends XataPlugin {
|
3052
3017
|
build(pluginOptions) {
|
@@ -3126,54 +3091,40 @@ var __accessCheck$1 = (obj, member, msg) => {
|
|
3126
3091
|
if (!member.has(obj))
|
3127
3092
|
throw TypeError("Cannot " + msg);
|
3128
3093
|
};
|
3129
|
-
var __privateGet$1 = (obj, member, getter) => {
|
3130
|
-
__accessCheck$1(obj, member, "read from private field");
|
3131
|
-
return getter ? getter.call(obj) : member.get(obj);
|
3132
|
-
};
|
3133
3094
|
var __privateAdd$1 = (obj, member, value) => {
|
3134
3095
|
if (member.has(obj))
|
3135
3096
|
throw TypeError("Cannot add the same private member more than once");
|
3136
3097
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
3137
3098
|
};
|
3138
|
-
var __privateSet$1 = (obj, member, value, setter) => {
|
3139
|
-
__accessCheck$1(obj, member, "write to private field");
|
3140
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
3141
|
-
return value;
|
3142
|
-
};
|
3143
3099
|
var __privateMethod$1 = (obj, member, method) => {
|
3144
3100
|
__accessCheck$1(obj, member, "access private method");
|
3145
3101
|
return method;
|
3146
3102
|
};
|
3147
|
-
var
|
3103
|
+
var _search, search_fn;
|
3148
3104
|
class SearchPlugin extends XataPlugin {
|
3149
|
-
constructor(db
|
3105
|
+
constructor(db) {
|
3150
3106
|
super();
|
3151
3107
|
this.db = db;
|
3152
3108
|
__privateAdd$1(this, _search);
|
3153
|
-
__privateAdd$1(this, _getSchemaTables);
|
3154
|
-
__privateAdd$1(this, _schemaTables, void 0);
|
3155
|
-
__privateSet$1(this, _schemaTables, schemaTables);
|
3156
3109
|
}
|
3157
3110
|
build(pluginOptions) {
|
3158
3111
|
return {
|
3159
3112
|
all: async (query, options = {}) => {
|
3160
3113
|
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3161
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3162
3114
|
return {
|
3163
3115
|
totalCount,
|
3164
3116
|
records: records.map((record) => {
|
3165
3117
|
const { table = "orphan" } = record.xata;
|
3166
|
-
return { table, record: initObject(this.db,
|
3118
|
+
return { table, record: initObject(this.db, pluginOptions.tables, table, record, ["*"]) };
|
3167
3119
|
})
|
3168
3120
|
};
|
3169
3121
|
},
|
3170
3122
|
byTable: async (query, options = {}) => {
|
3171
3123
|
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3172
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3173
3124
|
const records = rawRecords.reduce((acc, record) => {
|
3174
3125
|
const { table = "orphan" } = record.xata;
|
3175
3126
|
const items = acc[table] ?? [];
|
3176
|
-
const item = initObject(this.db,
|
3127
|
+
const item = initObject(this.db, pluginOptions.tables, table, record, ["*"]);
|
3177
3128
|
return { ...acc, [table]: [...items, item] };
|
3178
3129
|
}, {});
|
3179
3130
|
return { totalCount, records };
|
@@ -3181,29 +3132,17 @@ class SearchPlugin extends XataPlugin {
|
|
3181
3132
|
};
|
3182
3133
|
}
|
3183
3134
|
}
|
3184
|
-
_schemaTables = new WeakMap();
|
3185
3135
|
_search = new WeakSet();
|
3186
3136
|
search_fn = async function(query, options, pluginOptions) {
|
3187
3137
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3188
3138
|
const { records, totalCount } = await searchBranch({
|
3189
3139
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3190
|
-
// @ts-
|
3140
|
+
// @ts-expect-error Filter properties do not match inferred type
|
3191
3141
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
3192
3142
|
...pluginOptions
|
3193
3143
|
});
|
3194
3144
|
return { records, totalCount };
|
3195
3145
|
};
|
3196
|
-
_getSchemaTables = new WeakSet();
|
3197
|
-
getSchemaTables_fn = async function(pluginOptions) {
|
3198
|
-
if (__privateGet$1(this, _schemaTables))
|
3199
|
-
return __privateGet$1(this, _schemaTables);
|
3200
|
-
const { schema } = await getBranchDetails({
|
3201
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3202
|
-
...pluginOptions
|
3203
|
-
});
|
3204
|
-
__privateSet$1(this, _schemaTables, schema.tables);
|
3205
|
-
return schema.tables;
|
3206
|
-
};
|
3207
3146
|
|
3208
3147
|
function escapeElement(elementRepresentation) {
|
3209
3148
|
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
@@ -3265,17 +3204,31 @@ function prepareParams(param1, param2) {
|
|
3265
3204
|
|
3266
3205
|
class SQLPlugin extends XataPlugin {
|
3267
3206
|
build(pluginOptions) {
|
3268
|
-
return async (
|
3269
|
-
|
3270
|
-
|
3207
|
+
return async (query, ...parameters) => {
|
3208
|
+
if (!isParamsObject(query) && (!isTemplateStringsArray(query) || !Array.isArray(parameters))) {
|
3209
|
+
throw new Error("Invalid usage of `xata.sql`. Please use it as a tagged template or with an object.");
|
3210
|
+
}
|
3211
|
+
const { statement, params, consistency } = prepareParams(query, parameters);
|
3212
|
+
const {
|
3213
|
+
records,
|
3214
|
+
rows,
|
3215
|
+
warning,
|
3216
|
+
columns = []
|
3217
|
+
} = await sqlQuery({
|
3271
3218
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3272
3219
|
body: { statement, params, consistency },
|
3273
3220
|
...pluginOptions
|
3274
3221
|
});
|
3275
|
-
return { records, warning };
|
3222
|
+
return { records, rows, warning, columns };
|
3276
3223
|
};
|
3277
3224
|
}
|
3278
3225
|
}
|
3226
|
+
function isTemplateStringsArray(strings) {
|
3227
|
+
return Array.isArray(strings) && "raw" in strings && Array.isArray(strings.raw);
|
3228
|
+
}
|
3229
|
+
function isParamsObject(params) {
|
3230
|
+
return isObject(params) && "statement" in params;
|
3231
|
+
}
|
3279
3232
|
|
3280
3233
|
class TransactionPlugin extends XataPlugin {
|
3281
3234
|
build(pluginOptions) {
|
@@ -3317,7 +3270,7 @@ var __privateMethod = (obj, member, method) => {
|
|
3317
3270
|
const buildClient = (plugins) => {
|
3318
3271
|
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3319
3272
|
return _a = class {
|
3320
|
-
constructor(options = {},
|
3273
|
+
constructor(options = {}, tables) {
|
3321
3274
|
__privateAdd(this, _parseOptions);
|
3322
3275
|
__privateAdd(this, _getFetchProps);
|
3323
3276
|
__privateAdd(this, _options, void 0);
|
@@ -3325,14 +3278,15 @@ const buildClient = (plugins) => {
|
|
3325
3278
|
__privateSet(this, _options, safeOptions);
|
3326
3279
|
const pluginOptions = {
|
3327
3280
|
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3328
|
-
|
3329
|
-
|
3281
|
+
host: safeOptions.host,
|
3282
|
+
tables
|
3330
3283
|
};
|
3331
|
-
const db = new SchemaPlugin(
|
3332
|
-
const search = new SearchPlugin(db
|
3284
|
+
const db = new SchemaPlugin().build(pluginOptions);
|
3285
|
+
const search = new SearchPlugin(db).build(pluginOptions);
|
3333
3286
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
3334
3287
|
const sql = new SQLPlugin().build(pluginOptions);
|
3335
3288
|
const files = new FilesPlugin().build(pluginOptions);
|
3289
|
+
this.schema = { tables };
|
3336
3290
|
this.db = db;
|
3337
3291
|
this.search = search;
|
3338
3292
|
this.transactions = transactions;
|
@@ -3354,13 +3308,12 @@ const buildClient = (plugins) => {
|
|
3354
3308
|
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3355
3309
|
if (isBrowser && !enableBrowser) {
|
3356
3310
|
throw new Error(
|
3357
|
-
"You are trying to use Xata from the browser, which is potentially a non-secure environment.
|
3311
|
+
"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"
|
3358
3312
|
);
|
3359
3313
|
}
|
3360
3314
|
const fetch = getFetchImplementation(options?.fetch);
|
3361
3315
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3362
3316
|
const apiKey = options?.apiKey || getAPIKey();
|
3363
|
-
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3364
3317
|
const trace = options?.trace ?? defaultTrace;
|
3365
3318
|
const clientName = options?.clientName;
|
3366
3319
|
const host = options?.host ?? "production";
|
@@ -3396,7 +3349,6 @@ const buildClient = (plugins) => {
|
|
3396
3349
|
databaseURL,
|
3397
3350
|
apiKey,
|
3398
3351
|
branch,
|
3399
|
-
cache,
|
3400
3352
|
trace,
|
3401
3353
|
host,
|
3402
3354
|
clientID: generateUUID(),
|
@@ -3517,6 +3469,7 @@ exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
|
|
3517
3469
|
exports.PAGINATION_MAX_OFFSET = PAGINATION_MAX_OFFSET;
|
3518
3470
|
exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
|
3519
3471
|
exports.Page = Page;
|
3472
|
+
exports.PageRecordArray = PageRecordArray;
|
3520
3473
|
exports.Query = Query;
|
3521
3474
|
exports.RecordArray = RecordArray;
|
3522
3475
|
exports.RecordColumnTypes = RecordColumnTypes;
|
@@ -3526,7 +3479,6 @@ exports.SQLPlugin = SQLPlugin;
|
|
3526
3479
|
exports.SchemaPlugin = SchemaPlugin;
|
3527
3480
|
exports.SearchPlugin = SearchPlugin;
|
3528
3481
|
exports.Serializer = Serializer;
|
3529
|
-
exports.SimpleCache = SimpleCache;
|
3530
3482
|
exports.TransactionPlugin = TransactionPlugin;
|
3531
3483
|
exports.XataApiClient = XataApiClient;
|
3532
3484
|
exports.XataApiPlugin = XataApiPlugin;
|
@@ -3534,6 +3486,7 @@ exports.XataError = XataError;
|
|
3534
3486
|
exports.XataFile = XataFile;
|
3535
3487
|
exports.XataPlugin = XataPlugin;
|
3536
3488
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
3489
|
+
exports.adaptTable = adaptTable;
|
3537
3490
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
3538
3491
|
exports.addTableColumn = addTableColumn;
|
3539
3492
|
exports.aggregateTable = aggregateTable;
|
@@ -3578,6 +3531,7 @@ exports.equals = equals;
|
|
3578
3531
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
3579
3532
|
exports.exists = exists;
|
3580
3533
|
exports.fileAccess = fileAccess;
|
3534
|
+
exports.fileUpload = fileUpload;
|
3581
3535
|
exports.ge = ge;
|
3582
3536
|
exports.getAPIKey = getAPIKey;
|
3583
3537
|
exports.getAuthorizationCode = getAuthorizationCode;
|
@@ -3586,6 +3540,7 @@ exports.getBranchDetails = getBranchDetails;
|
|
3586
3540
|
exports.getBranchList = getBranchList;
|
3587
3541
|
exports.getBranchMetadata = getBranchMetadata;
|
3588
3542
|
exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
3543
|
+
exports.getBranchMigrationJobStatus = getBranchMigrationJobStatus;
|
3589
3544
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
3590
3545
|
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
3591
3546
|
exports.getBranchStats = getBranchStats;
|
@@ -3594,11 +3549,14 @@ exports.getColumn = getColumn;
|
|
3594
3549
|
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
3595
3550
|
exports.getDatabaseList = getDatabaseList;
|
3596
3551
|
exports.getDatabaseMetadata = getDatabaseMetadata;
|
3552
|
+
exports.getDatabaseSettings = getDatabaseSettings;
|
3597
3553
|
exports.getDatabaseURL = getDatabaseURL;
|
3598
3554
|
exports.getFile = getFile;
|
3599
3555
|
exports.getFileItem = getFileItem;
|
3600
3556
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
3601
3557
|
exports.getHostUrl = getHostUrl;
|
3558
|
+
exports.getMigrationHistory = getMigrationHistory;
|
3559
|
+
exports.getMigrationJobStatus = getMigrationJobStatus;
|
3602
3560
|
exports.getMigrationRequest = getMigrationRequest;
|
3603
3561
|
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
3604
3562
|
exports.getPreviewBranch = getPreviewBranch;
|
@@ -3636,7 +3594,6 @@ exports.isIdentifiable = isIdentifiable;
|
|
3636
3594
|
exports.isNot = isNot;
|
3637
3595
|
exports.isValidExpandedColumn = isValidExpandedColumn;
|
3638
3596
|
exports.isValidSelectableColumns = isValidSelectableColumns;
|
3639
|
-
exports.isXataRecord = isXataRecord;
|
3640
3597
|
exports.le = le;
|
3641
3598
|
exports.lessEquals = lessEquals;
|
3642
3599
|
exports.lessThan = lessThan;
|
@@ -3652,8 +3609,6 @@ exports.operationsByTag = operationsByTag;
|
|
3652
3609
|
exports.parseProviderString = parseProviderString;
|
3653
3610
|
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
3654
3611
|
exports.pattern = pattern;
|
3655
|
-
exports.pgRollJobStatus = pgRollJobStatus;
|
3656
|
-
exports.pgRollStatus = pgRollStatus;
|
3657
3612
|
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
3658
3613
|
exports.pushBranchMigrations = pushBranchMigrations;
|
3659
3614
|
exports.putFile = putFile;
|
@@ -3679,6 +3634,7 @@ exports.updateCluster = updateCluster;
|
|
3679
3634
|
exports.updateColumn = updateColumn;
|
3680
3635
|
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
3681
3636
|
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
3637
|
+
exports.updateDatabaseSettings = updateDatabaseSettings;
|
3682
3638
|
exports.updateMigrationRequest = updateMigrationRequest;
|
3683
3639
|
exports.updateOAuthAccessToken = updateOAuthAccessToken;
|
3684
3640
|
exports.updateRecordWithID = updateRecordWithID;
|