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