@xata.io/client 0.0.0-alpha.vf2894b5 → 0.0.0-alpha.vf2d4ede35f0fb2771332d1b20637a8546868103b
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 +3 -3
- package/CHANGELOG.md +99 -1
- package/dist/index.cjs +588 -459
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3481 -2715
- package/dist/index.mjs +574 -459
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -246,7 +246,7 @@ var __accessCheck$8 = (obj, member, msg) => {
|
|
246
246
|
if (!member.has(obj))
|
247
247
|
throw TypeError("Cannot " + msg);
|
248
248
|
};
|
249
|
-
var __privateGet$
|
249
|
+
var __privateGet$7 = (obj, member, getter) => {
|
250
250
|
__accessCheck$8(obj, member, "read from private field");
|
251
251
|
return getter ? getter.call(obj) : member.get(obj);
|
252
252
|
};
|
@@ -255,7 +255,7 @@ var __privateAdd$8 = (obj, member, value) => {
|
|
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$
|
258
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
259
259
|
__accessCheck$8(obj, member, "write to private field");
|
260
260
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
261
261
|
return value;
|
@@ -281,19 +281,19 @@ class ApiRequestPool {
|
|
281
281
|
__privateAdd$8(this, _fetch, void 0);
|
282
282
|
__privateAdd$8(this, _queue, void 0);
|
283
283
|
__privateAdd$8(this, _concurrency, void 0);
|
284
|
-
__privateSet$
|
285
|
-
__privateSet$
|
284
|
+
__privateSet$6(this, _queue, []);
|
285
|
+
__privateSet$6(this, _concurrency, concurrency);
|
286
286
|
this.running = 0;
|
287
287
|
this.started = 0;
|
288
288
|
}
|
289
289
|
setFetch(fetch2) {
|
290
|
-
__privateSet$
|
290
|
+
__privateSet$6(this, _fetch, fetch2);
|
291
291
|
}
|
292
292
|
getFetch() {
|
293
|
-
if (!__privateGet$
|
293
|
+
if (!__privateGet$7(this, _fetch)) {
|
294
294
|
throw new Error("Fetch not set");
|
295
295
|
}
|
296
|
-
return __privateGet$
|
296
|
+
return __privateGet$7(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$7(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$7(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$7(this, _concurrency)) {
|
340
|
+
const next = __privateGet$7(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)
|
@@ -723,7 +802,7 @@ function fetchSSERequest({
|
|
723
802
|
clientName,
|
724
803
|
xataAgentExtra
|
725
804
|
}) {
|
726
|
-
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
805
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
727
806
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
728
807
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
729
808
|
void fetchEventSource(url, {
|
@@ -766,12 +845,29 @@ function parseUrl(url) {
|
|
766
845
|
|
767
846
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
768
847
|
|
848
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/apply", method: "post", ...variables, signal });
|
849
|
+
const adaptTable = (variables, signal) => dataPlaneFetch({
|
850
|
+
url: "/db/{dbBranchName}/migrations/adapt/{tableName}",
|
851
|
+
method: "post",
|
852
|
+
...variables,
|
853
|
+
signal
|
854
|
+
});
|
855
|
+
const getBranchMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/status", method: "get", ...variables, signal });
|
856
|
+
const getMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/jobs/{jobId}", method: "get", ...variables, signal });
|
857
|
+
const getMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/history", method: "get", ...variables, signal });
|
769
858
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
770
859
|
url: "/dbs/{dbName}",
|
771
860
|
method: "get",
|
772
861
|
...variables,
|
773
862
|
signal
|
774
863
|
});
|
864
|
+
const getDatabaseSettings = (variables, signal) => dataPlaneFetch({
|
865
|
+
url: "/dbs/{dbName}/settings",
|
866
|
+
method: "get",
|
867
|
+
...variables,
|
868
|
+
signal
|
869
|
+
});
|
870
|
+
const updateDatabaseSettings = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/settings", method: "patch", ...variables, signal });
|
775
871
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
776
872
|
url: "/db/{dbBranchName}",
|
777
873
|
method: "get",
|
@@ -785,6 +881,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
785
881
|
...variables,
|
786
882
|
signal
|
787
883
|
});
|
884
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
885
|
+
url: "/db/{dbBranchName}/schema",
|
886
|
+
method: "get",
|
887
|
+
...variables,
|
888
|
+
signal
|
889
|
+
});
|
788
890
|
const copyBranch = (variables, signal) => dataPlaneFetch({
|
789
891
|
url: "/db/{dbBranchName}/copy",
|
790
892
|
method: "post",
|
@@ -966,6 +1068,12 @@ const fileAccess = (variables, signal) => dataPlaneFetch({
|
|
966
1068
|
...variables,
|
967
1069
|
signal
|
968
1070
|
});
|
1071
|
+
const fileUpload = (variables, signal) => dataPlaneFetch({
|
1072
|
+
url: "/file/{fileId}",
|
1073
|
+
method: "put",
|
1074
|
+
...variables,
|
1075
|
+
signal
|
1076
|
+
});
|
969
1077
|
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
970
1078
|
url: "/db/{dbBranchName}/sql",
|
971
1079
|
method: "post",
|
@@ -973,6 +1081,24 @@ const sqlQuery = (variables, signal) => dataPlaneFetch({
|
|
973
1081
|
signal
|
974
1082
|
});
|
975
1083
|
const operationsByTag$2 = {
|
1084
|
+
migrations: {
|
1085
|
+
applyMigration,
|
1086
|
+
adaptTable,
|
1087
|
+
getBranchMigrationJobStatus,
|
1088
|
+
getMigrationJobStatus,
|
1089
|
+
getMigrationHistory,
|
1090
|
+
getSchema,
|
1091
|
+
getBranchMigrationHistory,
|
1092
|
+
getBranchMigrationPlan,
|
1093
|
+
executeBranchMigrationPlan,
|
1094
|
+
getBranchSchemaHistory,
|
1095
|
+
compareBranchWithUserSchema,
|
1096
|
+
compareBranchSchemas,
|
1097
|
+
updateBranchSchema,
|
1098
|
+
previewBranchSchemaEdit,
|
1099
|
+
applyBranchSchemaEdit,
|
1100
|
+
pushBranchMigrations
|
1101
|
+
},
|
976
1102
|
branch: {
|
977
1103
|
getBranchList,
|
978
1104
|
getBranchDetails,
|
@@ -987,18 +1113,7 @@ const operationsByTag$2 = {
|
|
987
1113
|
removeGitBranchesEntry,
|
988
1114
|
resolveBranch
|
989
1115
|
},
|
990
|
-
|
991
|
-
getBranchMigrationHistory,
|
992
|
-
getBranchMigrationPlan,
|
993
|
-
executeBranchMigrationPlan,
|
994
|
-
getBranchSchemaHistory,
|
995
|
-
compareBranchWithUserSchema,
|
996
|
-
compareBranchSchemas,
|
997
|
-
updateBranchSchema,
|
998
|
-
previewBranchSchemaEdit,
|
999
|
-
applyBranchSchemaEdit,
|
1000
|
-
pushBranchMigrations
|
1001
|
-
},
|
1116
|
+
database: { getDatabaseSettings, updateDatabaseSettings },
|
1002
1117
|
migrationRequests: {
|
1003
1118
|
queryMigrationRequests,
|
1004
1119
|
createMigrationRequest,
|
@@ -1031,7 +1146,7 @@ const operationsByTag$2 = {
|
|
1031
1146
|
deleteRecord,
|
1032
1147
|
bulkInsertTableRecords
|
1033
1148
|
},
|
1034
|
-
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1149
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
|
1035
1150
|
searchAndFilter: {
|
1036
1151
|
queryTable,
|
1037
1152
|
searchBranch,
|
@@ -1140,6 +1255,8 @@ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
|
|
1140
1255
|
...variables,
|
1141
1256
|
signal
|
1142
1257
|
});
|
1258
|
+
const getWorkspaceSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/settings", method: "get", ...variables, signal });
|
1259
|
+
const updateWorkspaceSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/settings", method: "patch", ...variables, signal });
|
1143
1260
|
const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
|
1144
1261
|
const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
|
1145
1262
|
const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
|
@@ -1153,12 +1270,7 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
|
|
1153
1270
|
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
1154
1271
|
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
1155
1272
|
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1156
|
-
const listClusters = (variables, signal) => controlPlaneFetch({
|
1157
|
-
url: "/workspaces/{workspaceId}/clusters",
|
1158
|
-
method: "get",
|
1159
|
-
...variables,
|
1160
|
-
signal
|
1161
|
-
});
|
1273
|
+
const listClusters = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "get", ...variables, signal });
|
1162
1274
|
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
1163
1275
|
const getCluster = (variables, signal) => controlPlaneFetch({
|
1164
1276
|
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
@@ -1210,6 +1322,8 @@ const operationsByTag$1 = {
|
|
1210
1322
|
getWorkspace,
|
1211
1323
|
updateWorkspace,
|
1212
1324
|
deleteWorkspace,
|
1325
|
+
getWorkspaceSettings,
|
1326
|
+
updateWorkspaceSettings,
|
1213
1327
|
getWorkspaceMembersList,
|
1214
1328
|
updateWorkspaceMemberRole,
|
1215
1329
|
removeWorkspaceMember
|
@@ -1238,66 +1352,11 @@ const operationsByTag$1 = {
|
|
1238
1352
|
|
1239
1353
|
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
1240
1354
|
|
1241
|
-
function getHostUrl(provider, type) {
|
1242
|
-
if (isHostProviderAlias(provider)) {
|
1243
|
-
return providers[provider][type];
|
1244
|
-
} else if (isHostProviderBuilder(provider)) {
|
1245
|
-
return provider[type];
|
1246
|
-
}
|
1247
|
-
throw new Error("Invalid API provider");
|
1248
|
-
}
|
1249
|
-
const providers = {
|
1250
|
-
production: {
|
1251
|
-
main: "https://api.xata.io",
|
1252
|
-
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
1253
|
-
},
|
1254
|
-
staging: {
|
1255
|
-
main: "https://api.staging-xata.dev",
|
1256
|
-
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1257
|
-
},
|
1258
|
-
dev: {
|
1259
|
-
main: "https://api.dev-xata.dev",
|
1260
|
-
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
1261
|
-
}
|
1262
|
-
};
|
1263
|
-
function isHostProviderAlias(alias) {
|
1264
|
-
return isString(alias) && Object.keys(providers).includes(alias);
|
1265
|
-
}
|
1266
|
-
function isHostProviderBuilder(builder) {
|
1267
|
-
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
1268
|
-
}
|
1269
|
-
function parseProviderString(provider = "production") {
|
1270
|
-
if (isHostProviderAlias(provider)) {
|
1271
|
-
return provider;
|
1272
|
-
}
|
1273
|
-
const [main, workspaces] = provider.split(",");
|
1274
|
-
if (!main || !workspaces)
|
1275
|
-
return null;
|
1276
|
-
return { main, workspaces };
|
1277
|
-
}
|
1278
|
-
function buildProviderString(provider) {
|
1279
|
-
if (isHostProviderAlias(provider))
|
1280
|
-
return provider;
|
1281
|
-
return `${provider.main},${provider.workspaces}`;
|
1282
|
-
}
|
1283
|
-
function parseWorkspacesUrlParts(url) {
|
1284
|
-
if (!isString(url))
|
1285
|
-
return null;
|
1286
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1287
|
-
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1288
|
-
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1289
|
-
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1290
|
-
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
1291
|
-
if (!match)
|
1292
|
-
return null;
|
1293
|
-
return { workspace: match[1], region: match[2] };
|
1294
|
-
}
|
1295
|
-
|
1296
1355
|
var __accessCheck$7 = (obj, member, msg) => {
|
1297
1356
|
if (!member.has(obj))
|
1298
1357
|
throw TypeError("Cannot " + msg);
|
1299
1358
|
};
|
1300
|
-
var __privateGet$
|
1359
|
+
var __privateGet$6 = (obj, member, getter) => {
|
1301
1360
|
__accessCheck$7(obj, member, "read from private field");
|
1302
1361
|
return getter ? getter.call(obj) : member.get(obj);
|
1303
1362
|
};
|
@@ -1306,7 +1365,7 @@ var __privateAdd$7 = (obj, member, value) => {
|
|
1306
1365
|
throw TypeError("Cannot add the same private member more than once");
|
1307
1366
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1308
1367
|
};
|
1309
|
-
var __privateSet$
|
1368
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
1310
1369
|
__accessCheck$7(obj, member, "write to private field");
|
1311
1370
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1312
1371
|
return value;
|
@@ -1323,7 +1382,7 @@ class XataApiClient {
|
|
1323
1382
|
if (!apiKey) {
|
1324
1383
|
throw new Error("Could not resolve a valid apiKey");
|
1325
1384
|
}
|
1326
|
-
__privateSet$
|
1385
|
+
__privateSet$5(this, _extraProps, {
|
1327
1386
|
apiUrl: getHostUrl(provider, "main"),
|
1328
1387
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
1329
1388
|
fetch: getFetchImplementation(options.fetch),
|
@@ -1335,64 +1394,64 @@ class XataApiClient {
|
|
1335
1394
|
});
|
1336
1395
|
}
|
1337
1396
|
get user() {
|
1338
|
-
if (!__privateGet$
|
1339
|
-
__privateGet$
|
1340
|
-
return __privateGet$
|
1397
|
+
if (!__privateGet$6(this, _namespaces).user)
|
1398
|
+
__privateGet$6(this, _namespaces).user = new UserApi(__privateGet$6(this, _extraProps));
|
1399
|
+
return __privateGet$6(this, _namespaces).user;
|
1341
1400
|
}
|
1342
1401
|
get authentication() {
|
1343
|
-
if (!__privateGet$
|
1344
|
-
__privateGet$
|
1345
|
-
return __privateGet$
|
1402
|
+
if (!__privateGet$6(this, _namespaces).authentication)
|
1403
|
+
__privateGet$6(this, _namespaces).authentication = new AuthenticationApi(__privateGet$6(this, _extraProps));
|
1404
|
+
return __privateGet$6(this, _namespaces).authentication;
|
1346
1405
|
}
|
1347
1406
|
get workspaces() {
|
1348
|
-
if (!__privateGet$
|
1349
|
-
__privateGet$
|
1350
|
-
return __privateGet$
|
1407
|
+
if (!__privateGet$6(this, _namespaces).workspaces)
|
1408
|
+
__privateGet$6(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$6(this, _extraProps));
|
1409
|
+
return __privateGet$6(this, _namespaces).workspaces;
|
1351
1410
|
}
|
1352
1411
|
get invites() {
|
1353
|
-
if (!__privateGet$
|
1354
|
-
__privateGet$
|
1355
|
-
return __privateGet$
|
1412
|
+
if (!__privateGet$6(this, _namespaces).invites)
|
1413
|
+
__privateGet$6(this, _namespaces).invites = new InvitesApi(__privateGet$6(this, _extraProps));
|
1414
|
+
return __privateGet$6(this, _namespaces).invites;
|
1356
1415
|
}
|
1357
1416
|
get database() {
|
1358
|
-
if (!__privateGet$
|
1359
|
-
__privateGet$
|
1360
|
-
return __privateGet$
|
1417
|
+
if (!__privateGet$6(this, _namespaces).database)
|
1418
|
+
__privateGet$6(this, _namespaces).database = new DatabaseApi(__privateGet$6(this, _extraProps));
|
1419
|
+
return __privateGet$6(this, _namespaces).database;
|
1361
1420
|
}
|
1362
1421
|
get branches() {
|
1363
|
-
if (!__privateGet$
|
1364
|
-
__privateGet$
|
1365
|
-
return __privateGet$
|
1422
|
+
if (!__privateGet$6(this, _namespaces).branches)
|
1423
|
+
__privateGet$6(this, _namespaces).branches = new BranchApi(__privateGet$6(this, _extraProps));
|
1424
|
+
return __privateGet$6(this, _namespaces).branches;
|
1366
1425
|
}
|
1367
1426
|
get migrations() {
|
1368
|
-
if (!__privateGet$
|
1369
|
-
__privateGet$
|
1370
|
-
return __privateGet$
|
1427
|
+
if (!__privateGet$6(this, _namespaces).migrations)
|
1428
|
+
__privateGet$6(this, _namespaces).migrations = new MigrationsApi(__privateGet$6(this, _extraProps));
|
1429
|
+
return __privateGet$6(this, _namespaces).migrations;
|
1371
1430
|
}
|
1372
1431
|
get migrationRequests() {
|
1373
|
-
if (!__privateGet$
|
1374
|
-
__privateGet$
|
1375
|
-
return __privateGet$
|
1432
|
+
if (!__privateGet$6(this, _namespaces).migrationRequests)
|
1433
|
+
__privateGet$6(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$6(this, _extraProps));
|
1434
|
+
return __privateGet$6(this, _namespaces).migrationRequests;
|
1376
1435
|
}
|
1377
1436
|
get tables() {
|
1378
|
-
if (!__privateGet$
|
1379
|
-
__privateGet$
|
1380
|
-
return __privateGet$
|
1437
|
+
if (!__privateGet$6(this, _namespaces).tables)
|
1438
|
+
__privateGet$6(this, _namespaces).tables = new TableApi(__privateGet$6(this, _extraProps));
|
1439
|
+
return __privateGet$6(this, _namespaces).tables;
|
1381
1440
|
}
|
1382
1441
|
get records() {
|
1383
|
-
if (!__privateGet$
|
1384
|
-
__privateGet$
|
1385
|
-
return __privateGet$
|
1442
|
+
if (!__privateGet$6(this, _namespaces).records)
|
1443
|
+
__privateGet$6(this, _namespaces).records = new RecordsApi(__privateGet$6(this, _extraProps));
|
1444
|
+
return __privateGet$6(this, _namespaces).records;
|
1386
1445
|
}
|
1387
1446
|
get files() {
|
1388
|
-
if (!__privateGet$
|
1389
|
-
__privateGet$
|
1390
|
-
return __privateGet$
|
1447
|
+
if (!__privateGet$6(this, _namespaces).files)
|
1448
|
+
__privateGet$6(this, _namespaces).files = new FilesApi(__privateGet$6(this, _extraProps));
|
1449
|
+
return __privateGet$6(this, _namespaces).files;
|
1391
1450
|
}
|
1392
1451
|
get searchAndFilter() {
|
1393
|
-
if (!__privateGet$
|
1394
|
-
__privateGet$
|
1395
|
-
return __privateGet$
|
1452
|
+
if (!__privateGet$6(this, _namespaces).searchAndFilter)
|
1453
|
+
__privateGet$6(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$6(this, _extraProps));
|
1454
|
+
return __privateGet$6(this, _namespaces).searchAndFilter;
|
1396
1455
|
}
|
1397
1456
|
}
|
1398
1457
|
_extraProps = new WeakMap();
|
@@ -1694,6 +1753,30 @@ class BranchApi {
|
|
1694
1753
|
...this.extraProps
|
1695
1754
|
});
|
1696
1755
|
}
|
1756
|
+
pgRollMigrationHistory({
|
1757
|
+
workspace,
|
1758
|
+
region,
|
1759
|
+
database,
|
1760
|
+
branch
|
1761
|
+
}) {
|
1762
|
+
return operationsByTag.migrations.getMigrationHistory({
|
1763
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1764
|
+
...this.extraProps
|
1765
|
+
});
|
1766
|
+
}
|
1767
|
+
applyMigration({
|
1768
|
+
workspace,
|
1769
|
+
region,
|
1770
|
+
database,
|
1771
|
+
branch,
|
1772
|
+
migration
|
1773
|
+
}) {
|
1774
|
+
return operationsByTag.migrations.applyMigration({
|
1775
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1776
|
+
body: migration,
|
1777
|
+
...this.extraProps
|
1778
|
+
});
|
1779
|
+
}
|
1697
1780
|
}
|
1698
1781
|
class TableApi {
|
1699
1782
|
constructor(extraProps) {
|
@@ -2507,6 +2590,17 @@ class MigrationsApi {
|
|
2507
2590
|
...this.extraProps
|
2508
2591
|
});
|
2509
2592
|
}
|
2593
|
+
getSchema({
|
2594
|
+
workspace,
|
2595
|
+
region,
|
2596
|
+
database,
|
2597
|
+
branch
|
2598
|
+
}) {
|
2599
|
+
return operationsByTag.migrations.getSchema({
|
2600
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2601
|
+
...this.extraProps
|
2602
|
+
});
|
2603
|
+
}
|
2510
2604
|
}
|
2511
2605
|
class DatabaseApi {
|
2512
2606
|
constructor(extraProps) {
|
@@ -2617,75 +2711,6 @@ class XataApiPlugin {
|
|
2617
2711
|
class XataPlugin {
|
2618
2712
|
}
|
2619
2713
|
|
2620
|
-
class FilesPlugin extends XataPlugin {
|
2621
|
-
build(pluginOptions) {
|
2622
|
-
return {
|
2623
|
-
download: async (location) => {
|
2624
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2625
|
-
return await getFileItem({
|
2626
|
-
pathParams: {
|
2627
|
-
workspace: "{workspaceId}",
|
2628
|
-
dbBranchName: "{dbBranch}",
|
2629
|
-
region: "{region}",
|
2630
|
-
tableName: table ?? "",
|
2631
|
-
recordId: record ?? "",
|
2632
|
-
columnName: column ?? "",
|
2633
|
-
fileId
|
2634
|
-
},
|
2635
|
-
...pluginOptions,
|
2636
|
-
rawResponse: true
|
2637
|
-
});
|
2638
|
-
},
|
2639
|
-
upload: async (location, file) => {
|
2640
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2641
|
-
const contentType = getContentType(file);
|
2642
|
-
return await putFileItem({
|
2643
|
-
...pluginOptions,
|
2644
|
-
pathParams: {
|
2645
|
-
workspace: "{workspaceId}",
|
2646
|
-
dbBranchName: "{dbBranch}",
|
2647
|
-
region: "{region}",
|
2648
|
-
tableName: table ?? "",
|
2649
|
-
recordId: record ?? "",
|
2650
|
-
columnName: column ?? "",
|
2651
|
-
fileId
|
2652
|
-
},
|
2653
|
-
body: file,
|
2654
|
-
headers: { "Content-Type": contentType }
|
2655
|
-
});
|
2656
|
-
},
|
2657
|
-
delete: async (location) => {
|
2658
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2659
|
-
return await deleteFileItem({
|
2660
|
-
pathParams: {
|
2661
|
-
workspace: "{workspaceId}",
|
2662
|
-
dbBranchName: "{dbBranch}",
|
2663
|
-
region: "{region}",
|
2664
|
-
tableName: table ?? "",
|
2665
|
-
recordId: record ?? "",
|
2666
|
-
columnName: column ?? "",
|
2667
|
-
fileId
|
2668
|
-
},
|
2669
|
-
...pluginOptions
|
2670
|
-
});
|
2671
|
-
}
|
2672
|
-
};
|
2673
|
-
}
|
2674
|
-
}
|
2675
|
-
function getContentType(file) {
|
2676
|
-
if (typeof file === "string") {
|
2677
|
-
return "text/plain";
|
2678
|
-
}
|
2679
|
-
if (isBlob(file)) {
|
2680
|
-
return file.type;
|
2681
|
-
}
|
2682
|
-
try {
|
2683
|
-
return file.type;
|
2684
|
-
} catch (e) {
|
2685
|
-
}
|
2686
|
-
return "application/octet-stream";
|
2687
|
-
}
|
2688
|
-
|
2689
2714
|
function buildTransformString(transformations) {
|
2690
2715
|
return transformations.flatMap(
|
2691
2716
|
(t) => Object.entries(t).map(([key, value]) => {
|
@@ -2717,16 +2742,18 @@ function transformImage(url, ...transformations) {
|
|
2717
2742
|
class XataFile {
|
2718
2743
|
constructor(file) {
|
2719
2744
|
this.id = file.id;
|
2720
|
-
this.name = file.name
|
2721
|
-
this.mediaType = file.mediaType
|
2745
|
+
this.name = file.name;
|
2746
|
+
this.mediaType = file.mediaType;
|
2722
2747
|
this.base64Content = file.base64Content;
|
2723
|
-
this.enablePublicUrl = file.enablePublicUrl
|
2724
|
-
this.signedUrlTimeout = file.signedUrlTimeout
|
2725
|
-
this.
|
2726
|
-
this.
|
2727
|
-
this.
|
2748
|
+
this.enablePublicUrl = file.enablePublicUrl;
|
2749
|
+
this.signedUrlTimeout = file.signedUrlTimeout;
|
2750
|
+
this.uploadUrlTimeout = file.uploadUrlTimeout;
|
2751
|
+
this.size = file.size;
|
2752
|
+
this.version = file.version;
|
2753
|
+
this.url = file.url;
|
2728
2754
|
this.signedUrl = file.signedUrl;
|
2729
|
-
this.
|
2755
|
+
this.uploadUrl = file.uploadUrl;
|
2756
|
+
this.attributes = file.attributes;
|
2730
2757
|
}
|
2731
2758
|
static fromBuffer(buffer, options = {}) {
|
2732
2759
|
const base64Content = buffer.toString("base64");
|
@@ -2816,7 +2843,7 @@ class XataFile {
|
|
2816
2843
|
const parseInputFileEntry = async (entry) => {
|
2817
2844
|
if (!isDefined(entry))
|
2818
2845
|
return null;
|
2819
|
-
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2846
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
|
2820
2847
|
return compactObject({
|
2821
2848
|
id,
|
2822
2849
|
// Name cannot be an empty string in our API
|
@@ -2824,7 +2851,8 @@ const parseInputFileEntry = async (entry) => {
|
|
2824
2851
|
mediaType,
|
2825
2852
|
base64Content,
|
2826
2853
|
enablePublicUrl,
|
2827
|
-
signedUrlTimeout
|
2854
|
+
signedUrlTimeout,
|
2855
|
+
uploadUrlTimeout
|
2828
2856
|
});
|
2829
2857
|
};
|
2830
2858
|
|
@@ -2878,7 +2906,7 @@ var __accessCheck$6 = (obj, member, msg) => {
|
|
2878
2906
|
if (!member.has(obj))
|
2879
2907
|
throw TypeError("Cannot " + msg);
|
2880
2908
|
};
|
2881
|
-
var __privateGet$
|
2909
|
+
var __privateGet$5 = (obj, member, getter) => {
|
2882
2910
|
__accessCheck$6(obj, member, "read from private field");
|
2883
2911
|
return getter ? getter.call(obj) : member.get(obj);
|
2884
2912
|
};
|
@@ -2887,7 +2915,7 @@ var __privateAdd$6 = (obj, member, value) => {
|
|
2887
2915
|
throw TypeError("Cannot add the same private member more than once");
|
2888
2916
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
2889
2917
|
};
|
2890
|
-
var __privateSet$
|
2918
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
2891
2919
|
__accessCheck$6(obj, member, "write to private field");
|
2892
2920
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
2893
2921
|
return value;
|
@@ -2896,9 +2924,9 @@ var _query, _page;
|
|
2896
2924
|
class Page {
|
2897
2925
|
constructor(query, meta, records = []) {
|
2898
2926
|
__privateAdd$6(this, _query, void 0);
|
2899
|
-
__privateSet$
|
2927
|
+
__privateSet$4(this, _query, query);
|
2900
2928
|
this.meta = meta;
|
2901
|
-
this.records = new
|
2929
|
+
this.records = new PageRecordArray(this, records);
|
2902
2930
|
}
|
2903
2931
|
/**
|
2904
2932
|
* Retrieves the next page of results.
|
@@ -2907,7 +2935,7 @@ class Page {
|
|
2907
2935
|
* @returns The next page or results.
|
2908
2936
|
*/
|
2909
2937
|
async nextPage(size, offset) {
|
2910
|
-
return __privateGet$
|
2938
|
+
return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
2911
2939
|
}
|
2912
2940
|
/**
|
2913
2941
|
* Retrieves the previous page of results.
|
@@ -2916,7 +2944,7 @@ class Page {
|
|
2916
2944
|
* @returns The previous page or results.
|
2917
2945
|
*/
|
2918
2946
|
async previousPage(size, offset) {
|
2919
|
-
return __privateGet$
|
2947
|
+
return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
2920
2948
|
}
|
2921
2949
|
/**
|
2922
2950
|
* Retrieves the start page of results.
|
@@ -2925,7 +2953,7 @@ class Page {
|
|
2925
2953
|
* @returns The start page or results.
|
2926
2954
|
*/
|
2927
2955
|
async startPage(size, offset) {
|
2928
|
-
return __privateGet$
|
2956
|
+
return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
2929
2957
|
}
|
2930
2958
|
/**
|
2931
2959
|
* Retrieves the end page of results.
|
@@ -2934,7 +2962,7 @@ class Page {
|
|
2934
2962
|
* @returns The end page or results.
|
2935
2963
|
*/
|
2936
2964
|
async endPage(size, offset) {
|
2937
|
-
return __privateGet$
|
2965
|
+
return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
2938
2966
|
}
|
2939
2967
|
/**
|
2940
2968
|
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
@@ -2952,11 +2980,38 @@ const PAGINATION_DEFAULT_OFFSET = 0;
|
|
2952
2980
|
function isCursorPaginationOptions(options) {
|
2953
2981
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
2954
2982
|
}
|
2955
|
-
|
2983
|
+
class RecordArray extends Array {
|
2984
|
+
constructor(...args) {
|
2985
|
+
super(...RecordArray.parseConstructorParams(...args));
|
2986
|
+
}
|
2987
|
+
static parseConstructorParams(...args) {
|
2988
|
+
if (args.length === 1 && typeof args[0] === "number") {
|
2989
|
+
return new Array(args[0]);
|
2990
|
+
}
|
2991
|
+
if (args.length <= 1 && Array.isArray(args[0] ?? [])) {
|
2992
|
+
const result = args[0] ?? [];
|
2993
|
+
return new Array(...result);
|
2994
|
+
}
|
2995
|
+
return new Array(...args);
|
2996
|
+
}
|
2997
|
+
toArray() {
|
2998
|
+
return new Array(...this);
|
2999
|
+
}
|
3000
|
+
toSerializable() {
|
3001
|
+
return JSON.parse(this.toString());
|
3002
|
+
}
|
3003
|
+
toString() {
|
3004
|
+
return JSON.stringify(this.toArray());
|
3005
|
+
}
|
3006
|
+
map(callbackfn, thisArg) {
|
3007
|
+
return this.toArray().map(callbackfn, thisArg);
|
3008
|
+
}
|
3009
|
+
}
|
3010
|
+
const _PageRecordArray = class _PageRecordArray extends Array {
|
2956
3011
|
constructor(...args) {
|
2957
|
-
super(...
|
3012
|
+
super(..._PageRecordArray.parseConstructorParams(...args));
|
2958
3013
|
__privateAdd$6(this, _page, void 0);
|
2959
|
-
__privateSet$
|
3014
|
+
__privateSet$4(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
2960
3015
|
}
|
2961
3016
|
static parseConstructorParams(...args) {
|
2962
3017
|
if (args.length === 1 && typeof args[0] === "number") {
|
@@ -2986,8 +3041,8 @@ const _RecordArray = class _RecordArray extends Array {
|
|
2986
3041
|
* @returns A new array of objects
|
2987
3042
|
*/
|
2988
3043
|
async nextPage(size, offset) {
|
2989
|
-
const newPage = await __privateGet$
|
2990
|
-
return new
|
3044
|
+
const newPage = await __privateGet$5(this, _page).nextPage(size, offset);
|
3045
|
+
return new _PageRecordArray(newPage);
|
2991
3046
|
}
|
2992
3047
|
/**
|
2993
3048
|
* Retrieve previous page of records
|
@@ -2995,8 +3050,8 @@ const _RecordArray = class _RecordArray extends Array {
|
|
2995
3050
|
* @returns A new array of objects
|
2996
3051
|
*/
|
2997
3052
|
async previousPage(size, offset) {
|
2998
|
-
const newPage = await __privateGet$
|
2999
|
-
return new
|
3053
|
+
const newPage = await __privateGet$5(this, _page).previousPage(size, offset);
|
3054
|
+
return new _PageRecordArray(newPage);
|
3000
3055
|
}
|
3001
3056
|
/**
|
3002
3057
|
* Retrieve start page of records
|
@@ -3004,8 +3059,8 @@ const _RecordArray = class _RecordArray extends Array {
|
|
3004
3059
|
* @returns A new array of objects
|
3005
3060
|
*/
|
3006
3061
|
async startPage(size, offset) {
|
3007
|
-
const newPage = await __privateGet$
|
3008
|
-
return new
|
3062
|
+
const newPage = await __privateGet$5(this, _page).startPage(size, offset);
|
3063
|
+
return new _PageRecordArray(newPage);
|
3009
3064
|
}
|
3010
3065
|
/**
|
3011
3066
|
* Retrieve end page of records
|
@@ -3013,24 +3068,24 @@ const _RecordArray = class _RecordArray extends Array {
|
|
3013
3068
|
* @returns A new array of objects
|
3014
3069
|
*/
|
3015
3070
|
async endPage(size, offset) {
|
3016
|
-
const newPage = await __privateGet$
|
3017
|
-
return new
|
3071
|
+
const newPage = await __privateGet$5(this, _page).endPage(size, offset);
|
3072
|
+
return new _PageRecordArray(newPage);
|
3018
3073
|
}
|
3019
3074
|
/**
|
3020
3075
|
* @returns Boolean indicating if there is a next page
|
3021
3076
|
*/
|
3022
3077
|
hasNextPage() {
|
3023
|
-
return __privateGet$
|
3078
|
+
return __privateGet$5(this, _page).meta.page.more;
|
3024
3079
|
}
|
3025
3080
|
};
|
3026
3081
|
_page = new WeakMap();
|
3027
|
-
let
|
3082
|
+
let PageRecordArray = _PageRecordArray;
|
3028
3083
|
|
3029
3084
|
var __accessCheck$5 = (obj, member, msg) => {
|
3030
3085
|
if (!member.has(obj))
|
3031
3086
|
throw TypeError("Cannot " + msg);
|
3032
3087
|
};
|
3033
|
-
var __privateGet$
|
3088
|
+
var __privateGet$4 = (obj, member, getter) => {
|
3034
3089
|
__accessCheck$5(obj, member, "read from private field");
|
3035
3090
|
return getter ? getter.call(obj) : member.get(obj);
|
3036
3091
|
};
|
@@ -3039,7 +3094,7 @@ var __privateAdd$5 = (obj, member, value) => {
|
|
3039
3094
|
throw TypeError("Cannot add the same private member more than once");
|
3040
3095
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
3041
3096
|
};
|
3042
|
-
var __privateSet$
|
3097
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
3043
3098
|
__accessCheck$5(obj, member, "write to private field");
|
3044
3099
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
3045
3100
|
return value;
|
@@ -3057,25 +3112,25 @@ const _Query = class _Query {
|
|
3057
3112
|
__privateAdd$5(this, _data, { filter: {} });
|
3058
3113
|
// Implements pagination
|
3059
3114
|
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
3060
|
-
this.records = new
|
3061
|
-
__privateSet$
|
3115
|
+
this.records = new PageRecordArray(this, []);
|
3116
|
+
__privateSet$3(this, _table$1, table);
|
3062
3117
|
if (repository) {
|
3063
|
-
__privateSet$
|
3118
|
+
__privateSet$3(this, _repository, repository);
|
3064
3119
|
} else {
|
3065
|
-
__privateSet$
|
3120
|
+
__privateSet$3(this, _repository, this);
|
3066
3121
|
}
|
3067
3122
|
const parent = cleanParent(data, rawParent);
|
3068
|
-
__privateGet$
|
3069
|
-
__privateGet$
|
3070
|
-
__privateGet$
|
3071
|
-
__privateGet$
|
3072
|
-
__privateGet$
|
3073
|
-
__privateGet$
|
3074
|
-
__privateGet$
|
3075
|
-
__privateGet$
|
3076
|
-
__privateGet$
|
3077
|
-
__privateGet$
|
3078
|
-
__privateGet$
|
3123
|
+
__privateGet$4(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
3124
|
+
__privateGet$4(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
|
3125
|
+
__privateGet$4(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
|
3126
|
+
__privateGet$4(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
|
3127
|
+
__privateGet$4(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
3128
|
+
__privateGet$4(this, _data).sort = data.sort ?? parent?.sort;
|
3129
|
+
__privateGet$4(this, _data).columns = data.columns ?? parent?.columns;
|
3130
|
+
__privateGet$4(this, _data).consistency = data.consistency ?? parent?.consistency;
|
3131
|
+
__privateGet$4(this, _data).pagination = data.pagination ?? parent?.pagination;
|
3132
|
+
__privateGet$4(this, _data).cache = data.cache ?? parent?.cache;
|
3133
|
+
__privateGet$4(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
3079
3134
|
this.any = this.any.bind(this);
|
3080
3135
|
this.all = this.all.bind(this);
|
3081
3136
|
this.not = this.not.bind(this);
|
@@ -3086,10 +3141,10 @@ const _Query = class _Query {
|
|
3086
3141
|
Object.defineProperty(this, "repository", { enumerable: false });
|
3087
3142
|
}
|
3088
3143
|
getQueryOptions() {
|
3089
|
-
return __privateGet$
|
3144
|
+
return __privateGet$4(this, _data);
|
3090
3145
|
}
|
3091
3146
|
key() {
|
3092
|
-
const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$
|
3147
|
+
const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$4(this, _data);
|
3093
3148
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
3094
3149
|
return toBase64(key);
|
3095
3150
|
}
|
@@ -3100,7 +3155,7 @@ const _Query = class _Query {
|
|
3100
3155
|
*/
|
3101
3156
|
any(...queries) {
|
3102
3157
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
3103
|
-
return new _Query(__privateGet$
|
3158
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $any } }, __privateGet$4(this, _data));
|
3104
3159
|
}
|
3105
3160
|
/**
|
3106
3161
|
* Builds a new query object representing a logical AND between the given subqueries.
|
@@ -3109,7 +3164,7 @@ const _Query = class _Query {
|
|
3109
3164
|
*/
|
3110
3165
|
all(...queries) {
|
3111
3166
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
3112
|
-
return new _Query(__privateGet$
|
3167
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
|
3113
3168
|
}
|
3114
3169
|
/**
|
3115
3170
|
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
@@ -3118,7 +3173,7 @@ const _Query = class _Query {
|
|
3118
3173
|
*/
|
3119
3174
|
not(...queries) {
|
3120
3175
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
3121
|
-
return new _Query(__privateGet$
|
3176
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $not } }, __privateGet$4(this, _data));
|
3122
3177
|
}
|
3123
3178
|
/**
|
3124
3179
|
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
@@ -3127,25 +3182,25 @@ const _Query = class _Query {
|
|
3127
3182
|
*/
|
3128
3183
|
none(...queries) {
|
3129
3184
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
3130
|
-
return new _Query(__privateGet$
|
3185
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $none } }, __privateGet$4(this, _data));
|
3131
3186
|
}
|
3132
3187
|
filter(a, b) {
|
3133
3188
|
if (arguments.length === 1) {
|
3134
3189
|
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
3135
3190
|
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
3136
3191
|
}));
|
3137
|
-
const $all = compact([__privateGet$
|
3138
|
-
return new _Query(__privateGet$
|
3192
|
+
const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat(constraints));
|
3193
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
|
3139
3194
|
} else {
|
3140
3195
|
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
3141
|
-
const $all = compact([__privateGet$
|
3142
|
-
return new _Query(__privateGet$
|
3196
|
+
const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat(constraints));
|
3197
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
|
3143
3198
|
}
|
3144
3199
|
}
|
3145
3200
|
sort(column, direction = "asc") {
|
3146
|
-
const originalSort = [__privateGet$
|
3201
|
+
const originalSort = [__privateGet$4(this, _data).sort ?? []].flat();
|
3147
3202
|
const sort = [...originalSort, { column, direction }];
|
3148
|
-
return new _Query(__privateGet$
|
3203
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { sort }, __privateGet$4(this, _data));
|
3149
3204
|
}
|
3150
3205
|
/**
|
3151
3206
|
* Builds a new query specifying the set of columns to be returned in the query response.
|
@@ -3154,15 +3209,15 @@ const _Query = class _Query {
|
|
3154
3209
|
*/
|
3155
3210
|
select(columns) {
|
3156
3211
|
return new _Query(
|
3157
|
-
__privateGet$
|
3158
|
-
__privateGet$
|
3212
|
+
__privateGet$4(this, _repository),
|
3213
|
+
__privateGet$4(this, _table$1),
|
3159
3214
|
{ columns },
|
3160
|
-
__privateGet$
|
3215
|
+
__privateGet$4(this, _data)
|
3161
3216
|
);
|
3162
3217
|
}
|
3163
3218
|
getPaginated(options = {}) {
|
3164
|
-
const query = new _Query(__privateGet$
|
3165
|
-
return __privateGet$
|
3219
|
+
const query = new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), options, __privateGet$4(this, _data));
|
3220
|
+
return __privateGet$4(this, _repository).query(query);
|
3166
3221
|
}
|
3167
3222
|
/**
|
3168
3223
|
* Get results in an iterator
|
@@ -3199,7 +3254,7 @@ const _Query = class _Query {
|
|
3199
3254
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
3200
3255
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
3201
3256
|
}
|
3202
|
-
const array = new
|
3257
|
+
const array = new PageRecordArray(page, results.slice(0, size));
|
3203
3258
|
return array;
|
3204
3259
|
}
|
3205
3260
|
async getAll(options = {}) {
|
@@ -3208,7 +3263,7 @@ const _Query = class _Query {
|
|
3208
3263
|
for await (const page of this.getIterator({ ...rest, batchSize })) {
|
3209
3264
|
results.push(...page);
|
3210
3265
|
}
|
3211
|
-
return results;
|
3266
|
+
return new RecordArray(results);
|
3212
3267
|
}
|
3213
3268
|
async getFirst(options = {}) {
|
3214
3269
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
@@ -3223,12 +3278,12 @@ const _Query = class _Query {
|
|
3223
3278
|
async summarize(params = {}) {
|
3224
3279
|
const { summaries, summariesFilter, ...options } = params;
|
3225
3280
|
const query = new _Query(
|
3226
|
-
__privateGet$
|
3227
|
-
__privateGet$
|
3281
|
+
__privateGet$4(this, _repository),
|
3282
|
+
__privateGet$4(this, _table$1),
|
3228
3283
|
options,
|
3229
|
-
__privateGet$
|
3284
|
+
__privateGet$4(this, _data)
|
3230
3285
|
);
|
3231
|
-
return __privateGet$
|
3286
|
+
return __privateGet$4(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
3232
3287
|
}
|
3233
3288
|
/**
|
3234
3289
|
* Builds a new query object adding a cache TTL in milliseconds.
|
@@ -3236,7 +3291,7 @@ const _Query = class _Query {
|
|
3236
3291
|
* @returns A new Query object.
|
3237
3292
|
*/
|
3238
3293
|
cache(ttl) {
|
3239
|
-
return new _Query(__privateGet$
|
3294
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { cache: ttl }, __privateGet$4(this, _data));
|
3240
3295
|
}
|
3241
3296
|
/**
|
3242
3297
|
* Retrieve next page of records
|
@@ -3282,7 +3337,7 @@ _repository = new WeakMap();
|
|
3282
3337
|
_data = new WeakMap();
|
3283
3338
|
_cleanFilterConstraint = new WeakSet();
|
3284
3339
|
cleanFilterConstraint_fn = function(column, value) {
|
3285
|
-
const columnType = __privateGet$
|
3340
|
+
const columnType = __privateGet$4(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
3286
3341
|
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
3287
3342
|
return { $includes: value };
|
3288
3343
|
}
|
@@ -3308,7 +3363,6 @@ const RecordColumnTypes = [
|
|
3308
3363
|
"email",
|
3309
3364
|
"multiple",
|
3310
3365
|
"link",
|
3311
|
-
"object",
|
3312
3366
|
"datetime",
|
3313
3367
|
"vector",
|
3314
3368
|
"file[]",
|
@@ -3373,7 +3427,7 @@ var __accessCheck$4 = (obj, member, msg) => {
|
|
3373
3427
|
if (!member.has(obj))
|
3374
3428
|
throw TypeError("Cannot " + msg);
|
3375
3429
|
};
|
3376
|
-
var __privateGet$
|
3430
|
+
var __privateGet$3 = (obj, member, getter) => {
|
3377
3431
|
__accessCheck$4(obj, member, "read from private field");
|
3378
3432
|
return getter ? getter.call(obj) : member.get(obj);
|
3379
3433
|
};
|
@@ -3382,7 +3436,7 @@ var __privateAdd$4 = (obj, member, value) => {
|
|
3382
3436
|
throw TypeError("Cannot add the same private member more than once");
|
3383
3437
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
3384
3438
|
};
|
3385
|
-
var __privateSet$
|
3439
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
3386
3440
|
__accessCheck$4(obj, member, "write to private field");
|
3387
3441
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
3388
3442
|
return value;
|
@@ -3391,7 +3445,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
3391
3445
|
__accessCheck$4(obj, member, "access private method");
|
3392
3446
|
return method;
|
3393
3447
|
};
|
3394
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables
|
3448
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables, getSchemaTables_fn, _transformObjectToApi, transformObjectToApi_fn;
|
3395
3449
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
3396
3450
|
class Repository extends Query {
|
3397
3451
|
}
|
@@ -3412,31 +3466,31 @@ class RestRepository extends Query {
|
|
3412
3466
|
__privateAdd$4(this, _deleteRecords);
|
3413
3467
|
__privateAdd$4(this, _setCacheQuery);
|
3414
3468
|
__privateAdd$4(this, _getCacheQuery);
|
3415
|
-
__privateAdd$4(this, _getSchemaTables
|
3469
|
+
__privateAdd$4(this, _getSchemaTables);
|
3416
3470
|
__privateAdd$4(this, _transformObjectToApi);
|
3417
3471
|
__privateAdd$4(this, _table, void 0);
|
3418
3472
|
__privateAdd$4(this, _getFetchProps, void 0);
|
3419
3473
|
__privateAdd$4(this, _db, void 0);
|
3420
3474
|
__privateAdd$4(this, _cache, void 0);
|
3421
|
-
__privateAdd$4(this, _schemaTables
|
3475
|
+
__privateAdd$4(this, _schemaTables, void 0);
|
3422
3476
|
__privateAdd$4(this, _trace, void 0);
|
3423
|
-
__privateSet$
|
3424
|
-
__privateSet$
|
3425
|
-
__privateSet$
|
3426
|
-
__privateSet$
|
3427
|
-
__privateSet$
|
3477
|
+
__privateSet$2(this, _table, options.table);
|
3478
|
+
__privateSet$2(this, _db, options.db);
|
3479
|
+
__privateSet$2(this, _cache, options.pluginOptions.cache);
|
3480
|
+
__privateSet$2(this, _schemaTables, options.schemaTables);
|
3481
|
+
__privateSet$2(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
3428
3482
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
3429
|
-
__privateSet$
|
3483
|
+
__privateSet$2(this, _trace, async (name, fn, options2 = {}) => {
|
3430
3484
|
return trace(name, fn, {
|
3431
3485
|
...options2,
|
3432
|
-
[TraceAttributes.TABLE]: __privateGet$
|
3486
|
+
[TraceAttributes.TABLE]: __privateGet$3(this, _table),
|
3433
3487
|
[TraceAttributes.KIND]: "sdk-operation",
|
3434
3488
|
[TraceAttributes.VERSION]: VERSION
|
3435
3489
|
});
|
3436
3490
|
});
|
3437
3491
|
}
|
3438
3492
|
async create(a, b, c, d) {
|
3439
|
-
return __privateGet$
|
3493
|
+
return __privateGet$3(this, _trace).call(this, "create", async () => {
|
3440
3494
|
const ifVersion = parseIfVersion(b, c, d);
|
3441
3495
|
if (Array.isArray(a)) {
|
3442
3496
|
if (a.length === 0)
|
@@ -3466,7 +3520,7 @@ class RestRepository extends Query {
|
|
3466
3520
|
});
|
3467
3521
|
}
|
3468
3522
|
async read(a, b) {
|
3469
|
-
return __privateGet$
|
3523
|
+
return __privateGet$3(this, _trace).call(this, "read", async () => {
|
3470
3524
|
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3471
3525
|
if (Array.isArray(a)) {
|
3472
3526
|
if (a.length === 0)
|
@@ -3487,17 +3541,17 @@ class RestRepository extends Query {
|
|
3487
3541
|
workspace: "{workspaceId}",
|
3488
3542
|
dbBranchName: "{dbBranch}",
|
3489
3543
|
region: "{region}",
|
3490
|
-
tableName: __privateGet$
|
3544
|
+
tableName: __privateGet$3(this, _table),
|
3491
3545
|
recordId: id
|
3492
3546
|
},
|
3493
3547
|
queryParams: { columns },
|
3494
|
-
...__privateGet$
|
3548
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3495
3549
|
});
|
3496
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3550
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3497
3551
|
return initObject(
|
3498
|
-
__privateGet$
|
3552
|
+
__privateGet$3(this, _db),
|
3499
3553
|
schemaTables,
|
3500
|
-
__privateGet$
|
3554
|
+
__privateGet$3(this, _table),
|
3501
3555
|
response,
|
3502
3556
|
columns
|
3503
3557
|
);
|
@@ -3512,7 +3566,7 @@ class RestRepository extends Query {
|
|
3512
3566
|
});
|
3513
3567
|
}
|
3514
3568
|
async readOrThrow(a, b) {
|
3515
|
-
return __privateGet$
|
3569
|
+
return __privateGet$3(this, _trace).call(this, "readOrThrow", async () => {
|
3516
3570
|
const result = await this.read(a, b);
|
3517
3571
|
if (Array.isArray(result)) {
|
3518
3572
|
const missingIds = compact(
|
@@ -3531,7 +3585,7 @@ class RestRepository extends Query {
|
|
3531
3585
|
});
|
3532
3586
|
}
|
3533
3587
|
async update(a, b, c, d) {
|
3534
|
-
return __privateGet$
|
3588
|
+
return __privateGet$3(this, _trace).call(this, "update", async () => {
|
3535
3589
|
const ifVersion = parseIfVersion(b, c, d);
|
3536
3590
|
if (Array.isArray(a)) {
|
3537
3591
|
if (a.length === 0)
|
@@ -3564,7 +3618,7 @@ class RestRepository extends Query {
|
|
3564
3618
|
});
|
3565
3619
|
}
|
3566
3620
|
async updateOrThrow(a, b, c, d) {
|
3567
|
-
return __privateGet$
|
3621
|
+
return __privateGet$3(this, _trace).call(this, "updateOrThrow", async () => {
|
3568
3622
|
const result = await this.update(a, b, c, d);
|
3569
3623
|
if (Array.isArray(result)) {
|
3570
3624
|
const missingIds = compact(
|
@@ -3583,7 +3637,7 @@ class RestRepository extends Query {
|
|
3583
3637
|
});
|
3584
3638
|
}
|
3585
3639
|
async createOrUpdate(a, b, c, d) {
|
3586
|
-
return __privateGet$
|
3640
|
+
return __privateGet$3(this, _trace).call(this, "createOrUpdate", async () => {
|
3587
3641
|
const ifVersion = parseIfVersion(b, c, d);
|
3588
3642
|
if (Array.isArray(a)) {
|
3589
3643
|
if (a.length === 0)
|
@@ -3618,7 +3672,7 @@ class RestRepository extends Query {
|
|
3618
3672
|
});
|
3619
3673
|
}
|
3620
3674
|
async createOrReplace(a, b, c, d) {
|
3621
|
-
return __privateGet$
|
3675
|
+
return __privateGet$3(this, _trace).call(this, "createOrReplace", async () => {
|
3622
3676
|
const ifVersion = parseIfVersion(b, c, d);
|
3623
3677
|
if (Array.isArray(a)) {
|
3624
3678
|
if (a.length === 0)
|
@@ -3650,7 +3704,7 @@ class RestRepository extends Query {
|
|
3650
3704
|
});
|
3651
3705
|
}
|
3652
3706
|
async delete(a, b) {
|
3653
|
-
return __privateGet$
|
3707
|
+
return __privateGet$3(this, _trace).call(this, "delete", async () => {
|
3654
3708
|
if (Array.isArray(a)) {
|
3655
3709
|
if (a.length === 0)
|
3656
3710
|
return [];
|
@@ -3676,7 +3730,7 @@ class RestRepository extends Query {
|
|
3676
3730
|
});
|
3677
3731
|
}
|
3678
3732
|
async deleteOrThrow(a, b) {
|
3679
|
-
return __privateGet$
|
3733
|
+
return __privateGet$3(this, _trace).call(this, "deleteOrThrow", async () => {
|
3680
3734
|
const result = await this.delete(a, b);
|
3681
3735
|
if (Array.isArray(result)) {
|
3682
3736
|
const missingIds = compact(
|
@@ -3694,13 +3748,13 @@ class RestRepository extends Query {
|
|
3694
3748
|
});
|
3695
3749
|
}
|
3696
3750
|
async search(query, options = {}) {
|
3697
|
-
return __privateGet$
|
3698
|
-
const { records } = await searchTable({
|
3751
|
+
return __privateGet$3(this, _trace).call(this, "search", async () => {
|
3752
|
+
const { records, totalCount } = await searchTable({
|
3699
3753
|
pathParams: {
|
3700
3754
|
workspace: "{workspaceId}",
|
3701
3755
|
dbBranchName: "{dbBranch}",
|
3702
3756
|
region: "{region}",
|
3703
|
-
tableName: __privateGet$
|
3757
|
+
tableName: __privateGet$3(this, _table)
|
3704
3758
|
},
|
3705
3759
|
body: {
|
3706
3760
|
query,
|
@@ -3712,20 +3766,23 @@ class RestRepository extends Query {
|
|
3712
3766
|
page: options.page,
|
3713
3767
|
target: options.target
|
3714
3768
|
},
|
3715
|
-
...__privateGet$
|
3769
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3716
3770
|
});
|
3717
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3718
|
-
return
|
3771
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3772
|
+
return {
|
3773
|
+
records: records.map((item) => initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), item, ["*"])),
|
3774
|
+
totalCount
|
3775
|
+
};
|
3719
3776
|
});
|
3720
3777
|
}
|
3721
3778
|
async vectorSearch(column, query, options) {
|
3722
|
-
return __privateGet$
|
3723
|
-
const { records } = await vectorSearchTable({
|
3779
|
+
return __privateGet$3(this, _trace).call(this, "vectorSearch", async () => {
|
3780
|
+
const { records, totalCount } = await vectorSearchTable({
|
3724
3781
|
pathParams: {
|
3725
3782
|
workspace: "{workspaceId}",
|
3726
3783
|
dbBranchName: "{dbBranch}",
|
3727
3784
|
region: "{region}",
|
3728
|
-
tableName: __privateGet$
|
3785
|
+
tableName: __privateGet$3(this, _table)
|
3729
3786
|
},
|
3730
3787
|
body: {
|
3731
3788
|
column,
|
@@ -3734,29 +3791,32 @@ class RestRepository extends Query {
|
|
3734
3791
|
size: options?.size,
|
3735
3792
|
filter: options?.filter
|
3736
3793
|
},
|
3737
|
-
...__privateGet$
|
3794
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3738
3795
|
});
|
3739
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3740
|
-
return
|
3796
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3797
|
+
return {
|
3798
|
+
records: records.map((item) => initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), item, ["*"])),
|
3799
|
+
totalCount
|
3800
|
+
};
|
3741
3801
|
});
|
3742
3802
|
}
|
3743
3803
|
async aggregate(aggs, filter) {
|
3744
|
-
return __privateGet$
|
3804
|
+
return __privateGet$3(this, _trace).call(this, "aggregate", async () => {
|
3745
3805
|
const result = await aggregateTable({
|
3746
3806
|
pathParams: {
|
3747
3807
|
workspace: "{workspaceId}",
|
3748
3808
|
dbBranchName: "{dbBranch}",
|
3749
3809
|
region: "{region}",
|
3750
|
-
tableName: __privateGet$
|
3810
|
+
tableName: __privateGet$3(this, _table)
|
3751
3811
|
},
|
3752
3812
|
body: { aggs, filter },
|
3753
|
-
...__privateGet$
|
3813
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3754
3814
|
});
|
3755
3815
|
return result;
|
3756
3816
|
});
|
3757
3817
|
}
|
3758
3818
|
async query(query) {
|
3759
|
-
return __privateGet$
|
3819
|
+
return __privateGet$3(this, _trace).call(this, "query", async () => {
|
3760
3820
|
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
3761
3821
|
if (cacheQuery)
|
3762
3822
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
@@ -3766,7 +3826,7 @@ class RestRepository extends Query {
|
|
3766
3826
|
workspace: "{workspaceId}",
|
3767
3827
|
dbBranchName: "{dbBranch}",
|
3768
3828
|
region: "{region}",
|
3769
|
-
tableName: __privateGet$
|
3829
|
+
tableName: __privateGet$3(this, _table)
|
3770
3830
|
},
|
3771
3831
|
body: {
|
3772
3832
|
filter: cleanFilter(data.filter),
|
@@ -3776,14 +3836,14 @@ class RestRepository extends Query {
|
|
3776
3836
|
consistency: data.consistency
|
3777
3837
|
},
|
3778
3838
|
fetchOptions: data.fetchOptions,
|
3779
|
-
...__privateGet$
|
3839
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3780
3840
|
});
|
3781
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3841
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3782
3842
|
const records = objects.map(
|
3783
3843
|
(record) => initObject(
|
3784
|
-
__privateGet$
|
3844
|
+
__privateGet$3(this, _db),
|
3785
3845
|
schemaTables,
|
3786
|
-
__privateGet$
|
3846
|
+
__privateGet$3(this, _table),
|
3787
3847
|
record,
|
3788
3848
|
data.columns ?? ["*"]
|
3789
3849
|
)
|
@@ -3793,14 +3853,14 @@ class RestRepository extends Query {
|
|
3793
3853
|
});
|
3794
3854
|
}
|
3795
3855
|
async summarizeTable(query, summaries, summariesFilter) {
|
3796
|
-
return __privateGet$
|
3856
|
+
return __privateGet$3(this, _trace).call(this, "summarize", async () => {
|
3797
3857
|
const data = query.getQueryOptions();
|
3798
3858
|
const result = await summarizeTable({
|
3799
3859
|
pathParams: {
|
3800
3860
|
workspace: "{workspaceId}",
|
3801
3861
|
dbBranchName: "{dbBranch}",
|
3802
3862
|
region: "{region}",
|
3803
|
-
tableName: __privateGet$
|
3863
|
+
tableName: __privateGet$3(this, _table)
|
3804
3864
|
},
|
3805
3865
|
body: {
|
3806
3866
|
filter: cleanFilter(data.filter),
|
@@ -3811,9 +3871,15 @@ class RestRepository extends Query {
|
|
3811
3871
|
summaries,
|
3812
3872
|
summariesFilter
|
3813
3873
|
},
|
3814
|
-
...__privateGet$
|
3874
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3815
3875
|
});
|
3816
|
-
|
3876
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3877
|
+
return {
|
3878
|
+
...result,
|
3879
|
+
summaries: result.summaries.map(
|
3880
|
+
(summary) => initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), summary, data.columns ?? [])
|
3881
|
+
)
|
3882
|
+
};
|
3817
3883
|
});
|
3818
3884
|
}
|
3819
3885
|
ask(question, options) {
|
@@ -3823,7 +3889,7 @@ class RestRepository extends Query {
|
|
3823
3889
|
workspace: "{workspaceId}",
|
3824
3890
|
dbBranchName: "{dbBranch}",
|
3825
3891
|
region: "{region}",
|
3826
|
-
tableName: __privateGet$
|
3892
|
+
tableName: __privateGet$3(this, _table),
|
3827
3893
|
sessionId: options?.sessionId
|
3828
3894
|
},
|
3829
3895
|
body: {
|
@@ -3833,7 +3899,7 @@ class RestRepository extends Query {
|
|
3833
3899
|
search: options?.searchType === "keyword" ? options?.search : void 0,
|
3834
3900
|
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
3835
3901
|
},
|
3836
|
-
...__privateGet$
|
3902
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3837
3903
|
};
|
3838
3904
|
if (options?.onMessage) {
|
3839
3905
|
fetchSSERequest({
|
@@ -3854,7 +3920,7 @@ _table = new WeakMap();
|
|
3854
3920
|
_getFetchProps = new WeakMap();
|
3855
3921
|
_db = new WeakMap();
|
3856
3922
|
_cache = new WeakMap();
|
3857
|
-
_schemaTables
|
3923
|
+
_schemaTables = new WeakMap();
|
3858
3924
|
_trace = new WeakMap();
|
3859
3925
|
_insertRecordWithoutId = new WeakSet();
|
3860
3926
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
@@ -3864,14 +3930,14 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
3864
3930
|
workspace: "{workspaceId}",
|
3865
3931
|
dbBranchName: "{dbBranch}",
|
3866
3932
|
region: "{region}",
|
3867
|
-
tableName: __privateGet$
|
3933
|
+
tableName: __privateGet$3(this, _table)
|
3868
3934
|
},
|
3869
3935
|
queryParams: { columns },
|
3870
3936
|
body: record,
|
3871
|
-
...__privateGet$
|
3937
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3872
3938
|
});
|
3873
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3874
|
-
return initObject(__privateGet$
|
3939
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3940
|
+
return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
|
3875
3941
|
};
|
3876
3942
|
_insertRecordWithId = new WeakSet();
|
3877
3943
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
@@ -3883,21 +3949,21 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
3883
3949
|
workspace: "{workspaceId}",
|
3884
3950
|
dbBranchName: "{dbBranch}",
|
3885
3951
|
region: "{region}",
|
3886
|
-
tableName: __privateGet$
|
3952
|
+
tableName: __privateGet$3(this, _table),
|
3887
3953
|
recordId
|
3888
3954
|
},
|
3889
3955
|
body: record,
|
3890
3956
|
queryParams: { createOnly, columns, ifVersion },
|
3891
|
-
...__privateGet$
|
3957
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3892
3958
|
});
|
3893
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3894
|
-
return initObject(__privateGet$
|
3959
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3960
|
+
return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
|
3895
3961
|
};
|
3896
3962
|
_insertRecords = new WeakSet();
|
3897
3963
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
3898
3964
|
const operations = await promiseMap(objects, async (object) => {
|
3899
3965
|
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3900
|
-
return { insert: { table: __privateGet$
|
3966
|
+
return { insert: { table: __privateGet$3(this, _table), record, createOnly, ifVersion } };
|
3901
3967
|
});
|
3902
3968
|
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
3903
3969
|
const ids = [];
|
@@ -3909,7 +3975,7 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
3909
3975
|
region: "{region}"
|
3910
3976
|
},
|
3911
3977
|
body: { operations: operations2 },
|
3912
|
-
...__privateGet$
|
3978
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3913
3979
|
});
|
3914
3980
|
for (const result of results) {
|
3915
3981
|
if (result.operation === "insert") {
|
@@ -3932,15 +3998,15 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
3932
3998
|
workspace: "{workspaceId}",
|
3933
3999
|
dbBranchName: "{dbBranch}",
|
3934
4000
|
region: "{region}",
|
3935
|
-
tableName: __privateGet$
|
4001
|
+
tableName: __privateGet$3(this, _table),
|
3936
4002
|
recordId
|
3937
4003
|
},
|
3938
4004
|
queryParams: { columns, ifVersion },
|
3939
4005
|
body: record,
|
3940
|
-
...__privateGet$
|
4006
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3941
4007
|
});
|
3942
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3943
|
-
return initObject(__privateGet$
|
4008
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
4009
|
+
return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
|
3944
4010
|
} catch (e) {
|
3945
4011
|
if (isObject(e) && e.status === 404) {
|
3946
4012
|
return null;
|
@@ -3952,7 +4018,7 @@ _updateRecords = new WeakSet();
|
|
3952
4018
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
3953
4019
|
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
3954
4020
|
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3955
|
-
return { update: { table: __privateGet$
|
4021
|
+
return { update: { table: __privateGet$3(this, _table), id, ifVersion, upsert, fields } };
|
3956
4022
|
});
|
3957
4023
|
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
3958
4024
|
const ids = [];
|
@@ -3964,7 +4030,7 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
3964
4030
|
region: "{region}"
|
3965
4031
|
},
|
3966
4032
|
body: { operations: operations2 },
|
3967
|
-
...__privateGet$
|
4033
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3968
4034
|
});
|
3969
4035
|
for (const result of results) {
|
3970
4036
|
if (result.operation === "update") {
|
@@ -3985,15 +4051,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
3985
4051
|
workspace: "{workspaceId}",
|
3986
4052
|
dbBranchName: "{dbBranch}",
|
3987
4053
|
region: "{region}",
|
3988
|
-
tableName: __privateGet$
|
4054
|
+
tableName: __privateGet$3(this, _table),
|
3989
4055
|
recordId
|
3990
4056
|
},
|
3991
4057
|
queryParams: { columns, ifVersion },
|
3992
4058
|
body: object,
|
3993
|
-
...__privateGet$
|
4059
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3994
4060
|
});
|
3995
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3996
|
-
return initObject(__privateGet$
|
4061
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
4062
|
+
return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
|
3997
4063
|
};
|
3998
4064
|
_deleteRecord = new WeakSet();
|
3999
4065
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
@@ -4005,14 +4071,14 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
4005
4071
|
workspace: "{workspaceId}",
|
4006
4072
|
dbBranchName: "{dbBranch}",
|
4007
4073
|
region: "{region}",
|
4008
|
-
tableName: __privateGet$
|
4074
|
+
tableName: __privateGet$3(this, _table),
|
4009
4075
|
recordId
|
4010
4076
|
},
|
4011
4077
|
queryParams: { columns },
|
4012
|
-
...__privateGet$
|
4078
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
4013
4079
|
});
|
4014
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
4015
|
-
return initObject(__privateGet$
|
4080
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
4081
|
+
return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
|
4016
4082
|
} catch (e) {
|
4017
4083
|
if (isObject(e) && e.status === 404) {
|
4018
4084
|
return null;
|
@@ -4023,7 +4089,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
4023
4089
|
_deleteRecords = new WeakSet();
|
4024
4090
|
deleteRecords_fn = async function(recordIds) {
|
4025
4091
|
const chunkedOperations = chunk(
|
4026
|
-
compact(recordIds).map((id) => ({ delete: { table: __privateGet$
|
4092
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$3(this, _table), id } })),
|
4027
4093
|
BULK_OPERATION_MAX_SIZE
|
4028
4094
|
);
|
4029
4095
|
for (const operations of chunkedOperations) {
|
@@ -4034,44 +4100,44 @@ deleteRecords_fn = async function(recordIds) {
|
|
4034
4100
|
region: "{region}"
|
4035
4101
|
},
|
4036
4102
|
body: { operations },
|
4037
|
-
...__privateGet$
|
4103
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
4038
4104
|
});
|
4039
4105
|
}
|
4040
4106
|
};
|
4041
4107
|
_setCacheQuery = new WeakSet();
|
4042
4108
|
setCacheQuery_fn = async function(query, meta, records) {
|
4043
|
-
await __privateGet$
|
4109
|
+
await __privateGet$3(this, _cache)?.set(`query_${__privateGet$3(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
4044
4110
|
};
|
4045
4111
|
_getCacheQuery = new WeakSet();
|
4046
4112
|
getCacheQuery_fn = async function(query) {
|
4047
|
-
const key = `query_${__privateGet$
|
4048
|
-
const result = await __privateGet$
|
4113
|
+
const key = `query_${__privateGet$3(this, _table)}:${query.key()}`;
|
4114
|
+
const result = await __privateGet$3(this, _cache)?.get(key);
|
4049
4115
|
if (!result)
|
4050
4116
|
return null;
|
4051
|
-
const defaultTTL = __privateGet$
|
4117
|
+
const defaultTTL = __privateGet$3(this, _cache)?.defaultQueryTTL ?? -1;
|
4052
4118
|
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
4053
4119
|
if (ttl < 0)
|
4054
4120
|
return null;
|
4055
4121
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
4056
4122
|
return hasExpired ? null : result;
|
4057
4123
|
};
|
4058
|
-
_getSchemaTables
|
4059
|
-
getSchemaTables_fn
|
4060
|
-
if (__privateGet$
|
4061
|
-
return __privateGet$
|
4124
|
+
_getSchemaTables = new WeakSet();
|
4125
|
+
getSchemaTables_fn = async function() {
|
4126
|
+
if (__privateGet$3(this, _schemaTables))
|
4127
|
+
return __privateGet$3(this, _schemaTables);
|
4062
4128
|
const { schema } = await getBranchDetails({
|
4063
4129
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4064
|
-
...__privateGet$
|
4130
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
4065
4131
|
});
|
4066
|
-
__privateSet$
|
4132
|
+
__privateSet$2(this, _schemaTables, schema.tables);
|
4067
4133
|
return schema.tables;
|
4068
4134
|
};
|
4069
4135
|
_transformObjectToApi = new WeakSet();
|
4070
4136
|
transformObjectToApi_fn = async function(object) {
|
4071
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
4072
|
-
const schema = schemaTables.find((table) => table.name === __privateGet$
|
4137
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
4138
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$3(this, _table));
|
4073
4139
|
if (!schema)
|
4074
|
-
throw new Error(`Table ${__privateGet$
|
4140
|
+
throw new Error(`Table ${__privateGet$3(this, _table)} not found in schema`);
|
4075
4141
|
const result = {};
|
4076
4142
|
for (const [key, value] of Object.entries(object)) {
|
4077
4143
|
if (key === "xata")
|
@@ -4184,7 +4250,9 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4184
4250
|
record.delete = function() {
|
4185
4251
|
return db[table].delete(record["id"]);
|
4186
4252
|
};
|
4187
|
-
|
4253
|
+
if (metadata !== void 0) {
|
4254
|
+
record.xata = Object.freeze(metadata);
|
4255
|
+
}
|
4188
4256
|
record.getMetadata = function() {
|
4189
4257
|
return record.xata;
|
4190
4258
|
};
|
@@ -4225,7 +4293,7 @@ var __accessCheck$3 = (obj, member, msg) => {
|
|
4225
4293
|
if (!member.has(obj))
|
4226
4294
|
throw TypeError("Cannot " + msg);
|
4227
4295
|
};
|
4228
|
-
var __privateGet$
|
4296
|
+
var __privateGet$2 = (obj, member, getter) => {
|
4229
4297
|
__accessCheck$3(obj, member, "read from private field");
|
4230
4298
|
return getter ? getter.call(obj) : member.get(obj);
|
4231
4299
|
};
|
@@ -4234,7 +4302,7 @@ var __privateAdd$3 = (obj, member, value) => {
|
|
4234
4302
|
throw TypeError("Cannot add the same private member more than once");
|
4235
4303
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
4236
4304
|
};
|
4237
|
-
var __privateSet$
|
4305
|
+
var __privateSet$1 = (obj, member, value, setter) => {
|
4238
4306
|
__accessCheck$3(obj, member, "write to private field");
|
4239
4307
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
4240
4308
|
return value;
|
@@ -4243,29 +4311,29 @@ var _map;
|
|
4243
4311
|
class SimpleCache {
|
4244
4312
|
constructor(options = {}) {
|
4245
4313
|
__privateAdd$3(this, _map, void 0);
|
4246
|
-
__privateSet$
|
4314
|
+
__privateSet$1(this, _map, /* @__PURE__ */ new Map());
|
4247
4315
|
this.capacity = options.max ?? 500;
|
4248
4316
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
4249
4317
|
}
|
4250
4318
|
async getAll() {
|
4251
|
-
return Object.fromEntries(__privateGet$
|
4319
|
+
return Object.fromEntries(__privateGet$2(this, _map));
|
4252
4320
|
}
|
4253
4321
|
async get(key) {
|
4254
|
-
return __privateGet$
|
4322
|
+
return __privateGet$2(this, _map).get(key) ?? null;
|
4255
4323
|
}
|
4256
4324
|
async set(key, value) {
|
4257
4325
|
await this.delete(key);
|
4258
|
-
__privateGet$
|
4259
|
-
if (__privateGet$
|
4260
|
-
const leastRecentlyUsed = __privateGet$
|
4326
|
+
__privateGet$2(this, _map).set(key, value);
|
4327
|
+
if (__privateGet$2(this, _map).size > this.capacity) {
|
4328
|
+
const leastRecentlyUsed = __privateGet$2(this, _map).keys().next().value;
|
4261
4329
|
await this.delete(leastRecentlyUsed);
|
4262
4330
|
}
|
4263
4331
|
}
|
4264
4332
|
async delete(key) {
|
4265
|
-
__privateGet$
|
4333
|
+
__privateGet$2(this, _map).delete(key);
|
4266
4334
|
}
|
4267
4335
|
async clear() {
|
4268
|
-
return __privateGet$
|
4336
|
+
return __privateGet$2(this, _map).clear();
|
4269
4337
|
}
|
4270
4338
|
}
|
4271
4339
|
_map = new WeakMap();
|
@@ -4287,10 +4355,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
4287
4355
|
const startsWith = (value) => ({ $startsWith: value });
|
4288
4356
|
const endsWith = (value) => ({ $endsWith: value });
|
4289
4357
|
const pattern = (value) => ({ $pattern: value });
|
4358
|
+
const iPattern = (value) => ({ $iPattern: value });
|
4290
4359
|
const is = (value) => ({ $is: value });
|
4291
4360
|
const equals = is;
|
4292
4361
|
const isNot = (value) => ({ $isNot: value });
|
4293
4362
|
const contains = (value) => ({ $contains: value });
|
4363
|
+
const iContains = (value) => ({ $iContains: value });
|
4294
4364
|
const includes = (value) => ({ $includes: value });
|
4295
4365
|
const includesAll = (value) => ({ $includesAll: value });
|
4296
4366
|
const includesNone = (value) => ({ $includesNone: value });
|
@@ -4300,7 +4370,7 @@ var __accessCheck$2 = (obj, member, msg) => {
|
|
4300
4370
|
if (!member.has(obj))
|
4301
4371
|
throw TypeError("Cannot " + msg);
|
4302
4372
|
};
|
4303
|
-
var __privateGet$
|
4373
|
+
var __privateGet$1 = (obj, member, getter) => {
|
4304
4374
|
__accessCheck$2(obj, member, "read from private field");
|
4305
4375
|
return getter ? getter.call(obj) : member.get(obj);
|
4306
4376
|
};
|
@@ -4309,18 +4379,11 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
4309
4379
|
throw TypeError("Cannot add the same private member more than once");
|
4310
4380
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
4311
4381
|
};
|
4312
|
-
var
|
4313
|
-
__accessCheck$2(obj, member, "write to private field");
|
4314
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
4315
|
-
return value;
|
4316
|
-
};
|
4317
|
-
var _tables, _schemaTables$1;
|
4382
|
+
var _tables;
|
4318
4383
|
class SchemaPlugin extends XataPlugin {
|
4319
|
-
constructor(
|
4384
|
+
constructor() {
|
4320
4385
|
super();
|
4321
4386
|
__privateAdd$2(this, _tables, {});
|
4322
|
-
__privateAdd$2(this, _schemaTables$1, void 0);
|
4323
|
-
__privateSet$2(this, _schemaTables$1, schemaTables);
|
4324
4387
|
}
|
4325
4388
|
build(pluginOptions) {
|
4326
4389
|
const db = new Proxy(
|
@@ -4329,100 +4392,151 @@ class SchemaPlugin extends XataPlugin {
|
|
4329
4392
|
get: (_target, table) => {
|
4330
4393
|
if (!isString(table))
|
4331
4394
|
throw new Error("Invalid table name");
|
4332
|
-
if (__privateGet$
|
4333
|
-
__privateGet$
|
4395
|
+
if (__privateGet$1(this, _tables)[table] === void 0) {
|
4396
|
+
__privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: pluginOptions.tables });
|
4334
4397
|
}
|
4335
|
-
return __privateGet$
|
4398
|
+
return __privateGet$1(this, _tables)[table];
|
4336
4399
|
}
|
4337
4400
|
}
|
4338
4401
|
);
|
4339
|
-
const tableNames =
|
4402
|
+
const tableNames = pluginOptions.tables?.map(({ name }) => name) ?? [];
|
4340
4403
|
for (const table of tableNames) {
|
4341
|
-
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables:
|
4404
|
+
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: pluginOptions.tables });
|
4342
4405
|
}
|
4343
4406
|
return db;
|
4344
4407
|
}
|
4345
4408
|
}
|
4346
4409
|
_tables = new WeakMap();
|
4347
|
-
|
4410
|
+
|
4411
|
+
class FilesPlugin extends XataPlugin {
|
4412
|
+
build(pluginOptions) {
|
4413
|
+
return {
|
4414
|
+
download: async (location) => {
|
4415
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4416
|
+
return await getFileItem({
|
4417
|
+
pathParams: {
|
4418
|
+
workspace: "{workspaceId}",
|
4419
|
+
dbBranchName: "{dbBranch}",
|
4420
|
+
region: "{region}",
|
4421
|
+
tableName: table ?? "",
|
4422
|
+
recordId: record ?? "",
|
4423
|
+
columnName: column ?? "",
|
4424
|
+
fileId
|
4425
|
+
},
|
4426
|
+
...pluginOptions,
|
4427
|
+
rawResponse: true
|
4428
|
+
});
|
4429
|
+
},
|
4430
|
+
upload: async (location, file, options) => {
|
4431
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4432
|
+
const resolvedFile = await file;
|
4433
|
+
const contentType = options?.mediaType || getContentType(resolvedFile);
|
4434
|
+
const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
|
4435
|
+
return await putFileItem({
|
4436
|
+
...pluginOptions,
|
4437
|
+
pathParams: {
|
4438
|
+
workspace: "{workspaceId}",
|
4439
|
+
dbBranchName: "{dbBranch}",
|
4440
|
+
region: "{region}",
|
4441
|
+
tableName: table ?? "",
|
4442
|
+
recordId: record ?? "",
|
4443
|
+
columnName: column ?? "",
|
4444
|
+
fileId
|
4445
|
+
},
|
4446
|
+
body,
|
4447
|
+
headers: { "Content-Type": contentType }
|
4448
|
+
});
|
4449
|
+
},
|
4450
|
+
delete: async (location) => {
|
4451
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4452
|
+
return await deleteFileItem({
|
4453
|
+
pathParams: {
|
4454
|
+
workspace: "{workspaceId}",
|
4455
|
+
dbBranchName: "{dbBranch}",
|
4456
|
+
region: "{region}",
|
4457
|
+
tableName: table ?? "",
|
4458
|
+
recordId: record ?? "",
|
4459
|
+
columnName: column ?? "",
|
4460
|
+
fileId
|
4461
|
+
},
|
4462
|
+
...pluginOptions
|
4463
|
+
});
|
4464
|
+
}
|
4465
|
+
};
|
4466
|
+
}
|
4467
|
+
}
|
4468
|
+
function getContentType(file) {
|
4469
|
+
if (typeof file === "string") {
|
4470
|
+
return "text/plain";
|
4471
|
+
}
|
4472
|
+
if ("mediaType" in file && file.mediaType !== void 0) {
|
4473
|
+
return file.mediaType;
|
4474
|
+
}
|
4475
|
+
if (isBlob(file)) {
|
4476
|
+
return file.type;
|
4477
|
+
}
|
4478
|
+
try {
|
4479
|
+
return file.type;
|
4480
|
+
} catch (e) {
|
4481
|
+
}
|
4482
|
+
return "application/octet-stream";
|
4483
|
+
}
|
4348
4484
|
|
4349
4485
|
var __accessCheck$1 = (obj, member, msg) => {
|
4350
4486
|
if (!member.has(obj))
|
4351
4487
|
throw TypeError("Cannot " + msg);
|
4352
4488
|
};
|
4353
|
-
var __privateGet$1 = (obj, member, getter) => {
|
4354
|
-
__accessCheck$1(obj, member, "read from private field");
|
4355
|
-
return getter ? getter.call(obj) : member.get(obj);
|
4356
|
-
};
|
4357
4489
|
var __privateAdd$1 = (obj, member, value) => {
|
4358
4490
|
if (member.has(obj))
|
4359
4491
|
throw TypeError("Cannot add the same private member more than once");
|
4360
4492
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
4361
4493
|
};
|
4362
|
-
var __privateSet$1 = (obj, member, value, setter) => {
|
4363
|
-
__accessCheck$1(obj, member, "write to private field");
|
4364
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
4365
|
-
return value;
|
4366
|
-
};
|
4367
4494
|
var __privateMethod$1 = (obj, member, method) => {
|
4368
4495
|
__accessCheck$1(obj, member, "access private method");
|
4369
4496
|
return method;
|
4370
4497
|
};
|
4371
|
-
var
|
4498
|
+
var _search, search_fn;
|
4372
4499
|
class SearchPlugin extends XataPlugin {
|
4373
|
-
constructor(db
|
4500
|
+
constructor(db) {
|
4374
4501
|
super();
|
4375
4502
|
this.db = db;
|
4376
4503
|
__privateAdd$1(this, _search);
|
4377
|
-
__privateAdd$1(this, _getSchemaTables);
|
4378
|
-
__privateAdd$1(this, _schemaTables, void 0);
|
4379
|
-
__privateSet$1(this, _schemaTables, schemaTables);
|
4380
4504
|
}
|
4381
4505
|
build(pluginOptions) {
|
4382
4506
|
return {
|
4383
4507
|
all: async (query, options = {}) => {
|
4384
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4385
|
-
|
4386
|
-
|
4387
|
-
|
4388
|
-
|
4389
|
-
|
4508
|
+
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4509
|
+
return {
|
4510
|
+
totalCount,
|
4511
|
+
records: records.map((record) => {
|
4512
|
+
const { table = "orphan" } = record.xata;
|
4513
|
+
return { table, record: initObject(this.db, pluginOptions.tables, table, record, ["*"]) };
|
4514
|
+
})
|
4515
|
+
};
|
4390
4516
|
},
|
4391
4517
|
byTable: async (query, options = {}) => {
|
4392
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4393
|
-
const
|
4394
|
-
return records.reduce((acc, record) => {
|
4518
|
+
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4519
|
+
const records = rawRecords.reduce((acc, record) => {
|
4395
4520
|
const { table = "orphan" } = record.xata;
|
4396
4521
|
const items = acc[table] ?? [];
|
4397
|
-
const item = initObject(this.db,
|
4522
|
+
const item = initObject(this.db, pluginOptions.tables, table, record, ["*"]);
|
4398
4523
|
return { ...acc, [table]: [...items, item] };
|
4399
4524
|
}, {});
|
4525
|
+
return { totalCount, records };
|
4400
4526
|
}
|
4401
4527
|
};
|
4402
4528
|
}
|
4403
4529
|
}
|
4404
|
-
_schemaTables = new WeakMap();
|
4405
4530
|
_search = new WeakSet();
|
4406
4531
|
search_fn = async function(query, options, pluginOptions) {
|
4407
4532
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
4408
|
-
const { records } = await searchBranch({
|
4533
|
+
const { records, totalCount } = await searchBranch({
|
4409
4534
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4410
|
-
// @ts-
|
4535
|
+
// @ts-expect-error Filter properties do not match inferred type
|
4411
4536
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
4412
4537
|
...pluginOptions
|
4413
4538
|
});
|
4414
|
-
return records;
|
4415
|
-
};
|
4416
|
-
_getSchemaTables = new WeakSet();
|
4417
|
-
getSchemaTables_fn = async function(pluginOptions) {
|
4418
|
-
if (__privateGet$1(this, _schemaTables))
|
4419
|
-
return __privateGet$1(this, _schemaTables);
|
4420
|
-
const { schema } = await getBranchDetails({
|
4421
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4422
|
-
...pluginOptions
|
4423
|
-
});
|
4424
|
-
__privateSet$1(this, _schemaTables, schema.tables);
|
4425
|
-
return schema.tables;
|
4539
|
+
return { records, totalCount };
|
4426
4540
|
};
|
4427
4541
|
|
4428
4542
|
function escapeElement(elementRepresentation) {
|
@@ -4477,25 +4591,39 @@ function prepareParams(param1, param2) {
|
|
4477
4591
|
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
4478
4592
|
}
|
4479
4593
|
if (isObject(param1)) {
|
4480
|
-
const { statement, params, consistency } = param1;
|
4481
|
-
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
4594
|
+
const { statement, params, consistency, responseType } = param1;
|
4595
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency, responseType };
|
4482
4596
|
}
|
4483
4597
|
throw new Error("Invalid query");
|
4484
4598
|
}
|
4485
4599
|
|
4486
4600
|
class SQLPlugin extends XataPlugin {
|
4487
4601
|
build(pluginOptions) {
|
4488
|
-
return async (
|
4489
|
-
|
4490
|
-
|
4602
|
+
return async (query, ...parameters) => {
|
4603
|
+
if (!isParamsObject(query) && (!isTemplateStringsArray(query) || !Array.isArray(parameters))) {
|
4604
|
+
throw new Error("Invalid usage of `xata.sql`. Please use it as a tagged template or with an object.");
|
4605
|
+
}
|
4606
|
+
const { statement, params, consistency, responseType } = prepareParams(query, parameters);
|
4607
|
+
const {
|
4608
|
+
records,
|
4609
|
+
rows,
|
4610
|
+
warning,
|
4611
|
+
columns = []
|
4612
|
+
} = await sqlQuery({
|
4491
4613
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4492
|
-
body: { statement, params, consistency },
|
4614
|
+
body: { statement, params, consistency, responseType },
|
4493
4615
|
...pluginOptions
|
4494
4616
|
});
|
4495
|
-
return { records, warning };
|
4617
|
+
return { records, rows, warning, columns };
|
4496
4618
|
};
|
4497
4619
|
}
|
4498
4620
|
}
|
4621
|
+
function isTemplateStringsArray(strings) {
|
4622
|
+
return Array.isArray(strings) && "raw" in strings && Array.isArray(strings.raw);
|
4623
|
+
}
|
4624
|
+
function isParamsObject(params) {
|
4625
|
+
return isObject(params) && "statement" in params;
|
4626
|
+
}
|
4499
4627
|
|
4500
4628
|
class TransactionPlugin extends XataPlugin {
|
4501
4629
|
build(pluginOptions) {
|
@@ -4537,7 +4665,7 @@ var __privateMethod = (obj, member, method) => {
|
|
4537
4665
|
const buildClient = (plugins) => {
|
4538
4666
|
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
4539
4667
|
return _a = class {
|
4540
|
-
constructor(options = {},
|
4668
|
+
constructor(options = {}, tables) {
|
4541
4669
|
__privateAdd(this, _parseOptions);
|
4542
4670
|
__privateAdd(this, _getFetchProps);
|
4543
4671
|
__privateAdd(this, _options, void 0);
|
@@ -4546,13 +4674,15 @@ const buildClient = (plugins) => {
|
|
4546
4674
|
const pluginOptions = {
|
4547
4675
|
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
4548
4676
|
cache: safeOptions.cache,
|
4549
|
-
host: safeOptions.host
|
4677
|
+
host: safeOptions.host,
|
4678
|
+
tables
|
4550
4679
|
};
|
4551
|
-
const db = new SchemaPlugin(
|
4552
|
-
const search = new SearchPlugin(db
|
4680
|
+
const db = new SchemaPlugin().build(pluginOptions);
|
4681
|
+
const search = new SearchPlugin(db).build(pluginOptions);
|
4553
4682
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4554
4683
|
const sql = new SQLPlugin().build(pluginOptions);
|
4555
4684
|
const files = new FilesPlugin().build(pluginOptions);
|
4685
|
+
this.schema = { tables };
|
4556
4686
|
this.db = db;
|
4557
4687
|
this.search = search;
|
4558
4688
|
this.transactions = transactions;
|
@@ -4574,7 +4704,7 @@ const buildClient = (plugins) => {
|
|
4574
4704
|
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
4575
4705
|
if (isBrowser && !enableBrowser) {
|
4576
4706
|
throw new Error(
|
4577
|
-
"You are trying to use Xata from the browser, which is potentially a non-secure environment.
|
4707
|
+
"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"
|
4578
4708
|
);
|
4579
4709
|
}
|
4580
4710
|
const fetch = getFetchImplementation(options?.fetch);
|
@@ -4721,21 +4851,6 @@ const deserialize = (json) => {
|
|
4721
4851
|
return defaultSerializer.fromJSON(json);
|
4722
4852
|
};
|
4723
4853
|
|
4724
|
-
function buildWorkerRunner(config) {
|
4725
|
-
return function xataWorker(name, worker) {
|
4726
|
-
return async (...args) => {
|
4727
|
-
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
4728
|
-
const result = await fetch(url, {
|
4729
|
-
method: "POST",
|
4730
|
-
headers: { "Content-Type": "application/json" },
|
4731
|
-
body: serialize({ args })
|
4732
|
-
});
|
4733
|
-
const text = await result.text();
|
4734
|
-
return deserialize(text);
|
4735
|
-
};
|
4736
|
-
};
|
4737
|
-
}
|
4738
|
-
|
4739
4854
|
class XataError extends Error {
|
4740
4855
|
constructor(message, status) {
|
4741
4856
|
super(message);
|
@@ -4743,5 +4858,5 @@ class XataError extends Error {
|
|
4743
4858
|
}
|
4744
4859
|
}
|
4745
4860
|
|
4746
|
-
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, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString,
|
4861
|
+
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, SimpleCache, 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, getWorkspaceSettings, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, 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, updateWorkspaceSettings, upsertRecordWithID, vectorSearchTable };
|
4747
4862
|
//# sourceMappingURL=index.mjs.map
|