@xata.io/client 0.0.0-alpha.ve91fd39 → 0.0.0-alpha.ve95339c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-add-version.log +1 -1
- package/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +158 -2
- package/dist/index.cjs +1039 -104
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1867 -417
- package/dist/index.mjs +1011 -105
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -3
- package/.eslintrc.cjs +0 -13
- package/rollup.config.mjs +0 -44
- package/tsconfig.json +0 -23
package/dist/index.cjs
CHANGED
|
@@ -20,7 +20,8 @@ const TraceAttributes = {
|
|
|
20
20
|
HTTP_METHOD: "http.method",
|
|
21
21
|
HTTP_URL: "http.url",
|
|
22
22
|
HTTP_ROUTE: "http.route",
|
|
23
|
-
HTTP_TARGET: "http.target"
|
|
23
|
+
HTTP_TARGET: "http.target",
|
|
24
|
+
CLOUDFLARE_RAY_ID: "cf.ray"
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
function notEmpty(value) {
|
|
@@ -29,8 +30,18 @@ function notEmpty(value) {
|
|
|
29
30
|
function compact(arr) {
|
|
30
31
|
return arr.filter(notEmpty);
|
|
31
32
|
}
|
|
33
|
+
function compactObject(obj) {
|
|
34
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
|
35
|
+
}
|
|
36
|
+
function isBlob(value) {
|
|
37
|
+
try {
|
|
38
|
+
return value instanceof Blob;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
32
43
|
function isObject(value) {
|
|
33
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
44
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
|
34
45
|
}
|
|
35
46
|
function isDefined(value) {
|
|
36
47
|
return value !== null && value !== void 0;
|
|
@@ -85,6 +96,27 @@ function chunk(array, chunkSize) {
|
|
|
85
96
|
async function timeout(ms) {
|
|
86
97
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
87
98
|
}
|
|
99
|
+
function timeoutWithCancel(ms) {
|
|
100
|
+
let timeoutId;
|
|
101
|
+
const promise = new Promise((resolve) => {
|
|
102
|
+
timeoutId = setTimeout(() => {
|
|
103
|
+
resolve();
|
|
104
|
+
}, ms);
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
cancel: () => clearTimeout(timeoutId),
|
|
108
|
+
promise
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function promiseMap(inputValues, mapper) {
|
|
112
|
+
const reducer = (acc$, inputValue) => acc$.then(
|
|
113
|
+
(acc) => mapper(inputValue).then((result) => {
|
|
114
|
+
acc.push(result);
|
|
115
|
+
return acc;
|
|
116
|
+
})
|
|
117
|
+
);
|
|
118
|
+
return inputValues.reduce(reducer, Promise.resolve([]));
|
|
119
|
+
}
|
|
88
120
|
|
|
89
121
|
function getEnvironment() {
|
|
90
122
|
try {
|
|
@@ -184,7 +216,7 @@ function getAPIKey() {
|
|
|
184
216
|
function getBranch() {
|
|
185
217
|
try {
|
|
186
218
|
const { branch } = getEnvironment();
|
|
187
|
-
return branch
|
|
219
|
+
return branch;
|
|
188
220
|
} catch (err) {
|
|
189
221
|
return void 0;
|
|
190
222
|
}
|
|
@@ -235,13 +267,13 @@ var __privateMethod$4 = (obj, member, method) => {
|
|
|
235
267
|
return method;
|
|
236
268
|
};
|
|
237
269
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
|
270
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
|
238
271
|
function getFetchImplementation(userFetch) {
|
|
239
272
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
|
240
|
-
const
|
|
273
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
|
274
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
|
241
275
|
if (!fetchImpl) {
|
|
242
|
-
throw new Error(
|
|
243
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
|
244
|
-
);
|
|
276
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
|
245
277
|
}
|
|
246
278
|
return fetchImpl;
|
|
247
279
|
}
|
|
@@ -266,18 +298,22 @@ class ApiRequestPool {
|
|
|
266
298
|
return __privateGet$8(this, _fetch);
|
|
267
299
|
}
|
|
268
300
|
request(url, options) {
|
|
269
|
-
const start = new Date();
|
|
270
|
-
const
|
|
301
|
+
const start = /* @__PURE__ */ new Date();
|
|
302
|
+
const fetchImpl = this.getFetch();
|
|
271
303
|
const runRequest = async (stalled = false) => {
|
|
272
|
-
const
|
|
304
|
+
const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
|
|
305
|
+
const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
|
|
306
|
+
if (!response) {
|
|
307
|
+
throw new Error("Request timed out");
|
|
308
|
+
}
|
|
273
309
|
if (response.status === 429) {
|
|
274
310
|
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
|
275
311
|
await timeout(rateLimitReset * 1e3);
|
|
276
312
|
return await runRequest(true);
|
|
277
313
|
}
|
|
278
314
|
if (stalled) {
|
|
279
|
-
const stalledTime = new Date().getTime() - start.getTime();
|
|
280
|
-
console.warn(`A request to Xata hit
|
|
315
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
|
316
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
|
281
317
|
}
|
|
282
318
|
return response;
|
|
283
319
|
};
|
|
@@ -492,7 +528,7 @@ function defaultOnOpen(response) {
|
|
|
492
528
|
}
|
|
493
529
|
}
|
|
494
530
|
|
|
495
|
-
const VERSION = "0.
|
|
531
|
+
const VERSION = "0.26.7";
|
|
496
532
|
|
|
497
533
|
class ErrorWithCause extends Error {
|
|
498
534
|
constructor(message, options) {
|
|
@@ -568,6 +604,18 @@ function hostHeader(url) {
|
|
|
568
604
|
const { groups } = pattern.exec(url) ?? {};
|
|
569
605
|
return groups?.host ? { Host: groups.host } : {};
|
|
570
606
|
}
|
|
607
|
+
async function parseBody(body, headers) {
|
|
608
|
+
if (!isDefined(body))
|
|
609
|
+
return void 0;
|
|
610
|
+
if (isBlob(body) || typeof body.text === "function") {
|
|
611
|
+
return body;
|
|
612
|
+
}
|
|
613
|
+
const { "Content-Type": contentType } = headers ?? {};
|
|
614
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
|
615
|
+
return JSON.stringify(body);
|
|
616
|
+
}
|
|
617
|
+
return body;
|
|
618
|
+
}
|
|
571
619
|
const defaultClientID = generateUUID();
|
|
572
620
|
async function fetch$1({
|
|
573
621
|
url: path,
|
|
@@ -587,7 +635,8 @@ async function fetch$1({
|
|
|
587
635
|
sessionID,
|
|
588
636
|
clientName,
|
|
589
637
|
xataAgentExtra,
|
|
590
|
-
fetchOptions = {}
|
|
638
|
+
fetchOptions = {},
|
|
639
|
+
rawResponse = false
|
|
591
640
|
}) {
|
|
592
641
|
pool.setFetch(fetch2);
|
|
593
642
|
return await trace(
|
|
@@ -606,7 +655,7 @@ async function fetch$1({
|
|
|
606
655
|
isDefined(clientName) ? ["service", clientName] : void 0,
|
|
607
656
|
...Object.entries(xataAgentExtra ?? {})
|
|
608
657
|
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
|
609
|
-
const headers = {
|
|
658
|
+
const headers = compactObject({
|
|
610
659
|
"Accept-Encoding": "identity",
|
|
611
660
|
"Content-Type": "application/json",
|
|
612
661
|
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
|
@@ -615,11 +664,11 @@ async function fetch$1({
|
|
|
615
664
|
...customHeaders,
|
|
616
665
|
...hostHeader(fullUrl),
|
|
617
666
|
Authorization: `Bearer ${apiKey}`
|
|
618
|
-
};
|
|
667
|
+
});
|
|
619
668
|
const response = await pool.request(url, {
|
|
620
669
|
...fetchOptions,
|
|
621
670
|
method: method.toUpperCase(),
|
|
622
|
-
body:
|
|
671
|
+
body: await parseBody(body, headers),
|
|
623
672
|
headers,
|
|
624
673
|
signal
|
|
625
674
|
});
|
|
@@ -630,8 +679,12 @@ async function fetch$1({
|
|
|
630
679
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
|
631
680
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
|
632
681
|
[TraceAttributes.HTTP_HOST]: host,
|
|
633
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
|
682
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
|
683
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
|
634
684
|
});
|
|
685
|
+
const message = response.headers?.get("x-xata-message");
|
|
686
|
+
if (message)
|
|
687
|
+
console.warn(message);
|
|
635
688
|
if (response.status === 204) {
|
|
636
689
|
return {};
|
|
637
690
|
}
|
|
@@ -639,7 +692,7 @@ async function fetch$1({
|
|
|
639
692
|
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
|
640
693
|
}
|
|
641
694
|
try {
|
|
642
|
-
const jsonResponse = await response.json();
|
|
695
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
|
643
696
|
if (response.ok) {
|
|
644
697
|
return jsonResponse;
|
|
645
698
|
}
|
|
@@ -834,6 +887,42 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
|
834
887
|
});
|
|
835
888
|
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
|
836
889
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
|
890
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
|
891
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
|
892
|
+
method: "get",
|
|
893
|
+
...variables,
|
|
894
|
+
signal
|
|
895
|
+
});
|
|
896
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
|
897
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
|
898
|
+
method: "put",
|
|
899
|
+
...variables,
|
|
900
|
+
signal
|
|
901
|
+
});
|
|
902
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
|
903
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
|
904
|
+
method: "delete",
|
|
905
|
+
...variables,
|
|
906
|
+
signal
|
|
907
|
+
});
|
|
908
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
|
909
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
|
910
|
+
method: "get",
|
|
911
|
+
...variables,
|
|
912
|
+
signal
|
|
913
|
+
});
|
|
914
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
|
915
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
|
916
|
+
method: "put",
|
|
917
|
+
...variables,
|
|
918
|
+
signal
|
|
919
|
+
});
|
|
920
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
|
921
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
|
922
|
+
method: "delete",
|
|
923
|
+
...variables,
|
|
924
|
+
signal
|
|
925
|
+
});
|
|
837
926
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
|
838
927
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
|
839
928
|
method: "get",
|
|
@@ -863,12 +952,6 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
|
863
952
|
...variables,
|
|
864
953
|
signal
|
|
865
954
|
});
|
|
866
|
-
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
|
867
|
-
url: "/db/{dbBranchName}/sql",
|
|
868
|
-
method: "post",
|
|
869
|
-
...variables,
|
|
870
|
-
signal
|
|
871
|
-
});
|
|
872
955
|
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
|
873
956
|
const askTable = (variables, signal) => dataPlaneFetch({
|
|
874
957
|
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
|
@@ -876,8 +959,21 @@ const askTable = (variables, signal) => dataPlaneFetch({
|
|
|
876
959
|
...variables,
|
|
877
960
|
signal
|
|
878
961
|
});
|
|
962
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
|
879
963
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
|
880
964
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
|
965
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
|
966
|
+
url: "/file/{fileId}",
|
|
967
|
+
method: "get",
|
|
968
|
+
...variables,
|
|
969
|
+
signal
|
|
970
|
+
});
|
|
971
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
|
972
|
+
url: "/db/{dbBranchName}/sql",
|
|
973
|
+
method: "post",
|
|
974
|
+
...variables,
|
|
975
|
+
signal
|
|
976
|
+
});
|
|
881
977
|
const operationsByTag$2 = {
|
|
882
978
|
branch: {
|
|
883
979
|
getBranchList,
|
|
@@ -937,20 +1033,24 @@ const operationsByTag$2 = {
|
|
|
937
1033
|
deleteRecord,
|
|
938
1034
|
bulkInsertTableRecords
|
|
939
1035
|
},
|
|
1036
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
|
940
1037
|
searchAndFilter: {
|
|
941
1038
|
queryTable,
|
|
942
1039
|
searchBranch,
|
|
943
1040
|
searchTable,
|
|
944
|
-
sqlQuery,
|
|
945
1041
|
vectorSearchTable,
|
|
946
1042
|
askTable,
|
|
1043
|
+
askTableSession,
|
|
947
1044
|
summarizeTable,
|
|
948
1045
|
aggregateTable
|
|
949
|
-
}
|
|
1046
|
+
},
|
|
1047
|
+
sql: { sqlQuery }
|
|
950
1048
|
};
|
|
951
1049
|
|
|
952
1050
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
|
953
1051
|
|
|
1052
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
|
1053
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
|
954
1054
|
const getUser = (variables, signal) => controlPlaneFetch({
|
|
955
1055
|
url: "/user",
|
|
956
1056
|
method: "get",
|
|
@@ -987,6 +1087,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
|
987
1087
|
...variables,
|
|
988
1088
|
signal
|
|
989
1089
|
});
|
|
1090
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
|
1091
|
+
url: "/user/oauth/clients",
|
|
1092
|
+
method: "get",
|
|
1093
|
+
...variables,
|
|
1094
|
+
signal
|
|
1095
|
+
});
|
|
1096
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
|
1097
|
+
url: "/user/oauth/clients/{clientId}",
|
|
1098
|
+
method: "delete",
|
|
1099
|
+
...variables,
|
|
1100
|
+
signal
|
|
1101
|
+
});
|
|
1102
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
|
1103
|
+
url: "/user/oauth/tokens",
|
|
1104
|
+
method: "get",
|
|
1105
|
+
...variables,
|
|
1106
|
+
signal
|
|
1107
|
+
});
|
|
1108
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
|
1109
|
+
url: "/user/oauth/tokens/{token}",
|
|
1110
|
+
method: "delete",
|
|
1111
|
+
...variables,
|
|
1112
|
+
signal
|
|
1113
|
+
});
|
|
1114
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
|
990
1115
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
|
991
1116
|
url: "/workspaces",
|
|
992
1117
|
method: "get",
|
|
@@ -1030,6 +1155,20 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
|
|
|
1030
1155
|
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
|
1031
1156
|
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
|
1032
1157
|
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
|
1158
|
+
const listClusters = (variables, signal) => controlPlaneFetch({
|
|
1159
|
+
url: "/workspaces/{workspaceId}/clusters",
|
|
1160
|
+
method: "get",
|
|
1161
|
+
...variables,
|
|
1162
|
+
signal
|
|
1163
|
+
});
|
|
1164
|
+
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
|
1165
|
+
const getCluster = (variables, signal) => controlPlaneFetch({
|
|
1166
|
+
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
|
1167
|
+
method: "get",
|
|
1168
|
+
...variables,
|
|
1169
|
+
signal
|
|
1170
|
+
});
|
|
1171
|
+
const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
|
|
1033
1172
|
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
|
1034
1173
|
url: "/workspaces/{workspaceId}/dbs",
|
|
1035
1174
|
method: "get",
|
|
@@ -1045,6 +1184,7 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
|
1045
1184
|
});
|
|
1046
1185
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
|
1047
1186
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
|
1187
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
|
1048
1188
|
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
|
1049
1189
|
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
|
1050
1190
|
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
|
@@ -1055,6 +1195,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
|
1055
1195
|
signal
|
|
1056
1196
|
});
|
|
1057
1197
|
const operationsByTag$1 = {
|
|
1198
|
+
oAuth: {
|
|
1199
|
+
getAuthorizationCode,
|
|
1200
|
+
grantAuthorizationCode,
|
|
1201
|
+
getUserOAuthClients,
|
|
1202
|
+
deleteUserOAuthClient,
|
|
1203
|
+
getUserOAuthAccessTokens,
|
|
1204
|
+
deleteOAuthAccessToken,
|
|
1205
|
+
updateOAuthAccessToken
|
|
1206
|
+
},
|
|
1058
1207
|
users: { getUser, updateUser, deleteUser },
|
|
1059
1208
|
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
|
1060
1209
|
workspaces: {
|
|
@@ -1074,12 +1223,14 @@ const operationsByTag$1 = {
|
|
|
1074
1223
|
acceptWorkspaceMemberInvite,
|
|
1075
1224
|
resendWorkspaceMemberInvite
|
|
1076
1225
|
},
|
|
1226
|
+
xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
|
|
1077
1227
|
databases: {
|
|
1078
1228
|
getDatabaseList,
|
|
1079
1229
|
createDatabase,
|
|
1080
1230
|
deleteDatabase,
|
|
1081
1231
|
getDatabaseMetadata,
|
|
1082
1232
|
updateDatabaseMetadata,
|
|
1233
|
+
renameDatabase,
|
|
1083
1234
|
getDatabaseGithubSettings,
|
|
1084
1235
|
updateDatabaseGithubSettings,
|
|
1085
1236
|
deleteDatabaseGithubSettings,
|
|
@@ -1235,6 +1386,11 @@ class XataApiClient {
|
|
|
1235
1386
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
|
1236
1387
|
return __privateGet$7(this, _namespaces).records;
|
|
1237
1388
|
}
|
|
1389
|
+
get files() {
|
|
1390
|
+
if (!__privateGet$7(this, _namespaces).files)
|
|
1391
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
|
1392
|
+
return __privateGet$7(this, _namespaces).files;
|
|
1393
|
+
}
|
|
1238
1394
|
get searchAndFilter() {
|
|
1239
1395
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
|
1240
1396
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
|
@@ -1812,6 +1968,164 @@ class RecordsApi {
|
|
|
1812
1968
|
});
|
|
1813
1969
|
}
|
|
1814
1970
|
}
|
|
1971
|
+
class FilesApi {
|
|
1972
|
+
constructor(extraProps) {
|
|
1973
|
+
this.extraProps = extraProps;
|
|
1974
|
+
}
|
|
1975
|
+
getFileItem({
|
|
1976
|
+
workspace,
|
|
1977
|
+
region,
|
|
1978
|
+
database,
|
|
1979
|
+
branch,
|
|
1980
|
+
table,
|
|
1981
|
+
record,
|
|
1982
|
+
column,
|
|
1983
|
+
fileId
|
|
1984
|
+
}) {
|
|
1985
|
+
return operationsByTag.files.getFileItem({
|
|
1986
|
+
pathParams: {
|
|
1987
|
+
workspace,
|
|
1988
|
+
region,
|
|
1989
|
+
dbBranchName: `${database}:${branch}`,
|
|
1990
|
+
tableName: table,
|
|
1991
|
+
recordId: record,
|
|
1992
|
+
columnName: column,
|
|
1993
|
+
fileId
|
|
1994
|
+
},
|
|
1995
|
+
...this.extraProps
|
|
1996
|
+
});
|
|
1997
|
+
}
|
|
1998
|
+
putFileItem({
|
|
1999
|
+
workspace,
|
|
2000
|
+
region,
|
|
2001
|
+
database,
|
|
2002
|
+
branch,
|
|
2003
|
+
table,
|
|
2004
|
+
record,
|
|
2005
|
+
column,
|
|
2006
|
+
fileId,
|
|
2007
|
+
file
|
|
2008
|
+
}) {
|
|
2009
|
+
return operationsByTag.files.putFileItem({
|
|
2010
|
+
pathParams: {
|
|
2011
|
+
workspace,
|
|
2012
|
+
region,
|
|
2013
|
+
dbBranchName: `${database}:${branch}`,
|
|
2014
|
+
tableName: table,
|
|
2015
|
+
recordId: record,
|
|
2016
|
+
columnName: column,
|
|
2017
|
+
fileId
|
|
2018
|
+
},
|
|
2019
|
+
// @ts-ignore
|
|
2020
|
+
body: file,
|
|
2021
|
+
...this.extraProps
|
|
2022
|
+
});
|
|
2023
|
+
}
|
|
2024
|
+
deleteFileItem({
|
|
2025
|
+
workspace,
|
|
2026
|
+
region,
|
|
2027
|
+
database,
|
|
2028
|
+
branch,
|
|
2029
|
+
table,
|
|
2030
|
+
record,
|
|
2031
|
+
column,
|
|
2032
|
+
fileId
|
|
2033
|
+
}) {
|
|
2034
|
+
return operationsByTag.files.deleteFileItem({
|
|
2035
|
+
pathParams: {
|
|
2036
|
+
workspace,
|
|
2037
|
+
region,
|
|
2038
|
+
dbBranchName: `${database}:${branch}`,
|
|
2039
|
+
tableName: table,
|
|
2040
|
+
recordId: record,
|
|
2041
|
+
columnName: column,
|
|
2042
|
+
fileId
|
|
2043
|
+
},
|
|
2044
|
+
...this.extraProps
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
getFile({
|
|
2048
|
+
workspace,
|
|
2049
|
+
region,
|
|
2050
|
+
database,
|
|
2051
|
+
branch,
|
|
2052
|
+
table,
|
|
2053
|
+
record,
|
|
2054
|
+
column
|
|
2055
|
+
}) {
|
|
2056
|
+
return operationsByTag.files.getFile({
|
|
2057
|
+
pathParams: {
|
|
2058
|
+
workspace,
|
|
2059
|
+
region,
|
|
2060
|
+
dbBranchName: `${database}:${branch}`,
|
|
2061
|
+
tableName: table,
|
|
2062
|
+
recordId: record,
|
|
2063
|
+
columnName: column
|
|
2064
|
+
},
|
|
2065
|
+
...this.extraProps
|
|
2066
|
+
});
|
|
2067
|
+
}
|
|
2068
|
+
putFile({
|
|
2069
|
+
workspace,
|
|
2070
|
+
region,
|
|
2071
|
+
database,
|
|
2072
|
+
branch,
|
|
2073
|
+
table,
|
|
2074
|
+
record,
|
|
2075
|
+
column,
|
|
2076
|
+
file
|
|
2077
|
+
}) {
|
|
2078
|
+
return operationsByTag.files.putFile({
|
|
2079
|
+
pathParams: {
|
|
2080
|
+
workspace,
|
|
2081
|
+
region,
|
|
2082
|
+
dbBranchName: `${database}:${branch}`,
|
|
2083
|
+
tableName: table,
|
|
2084
|
+
recordId: record,
|
|
2085
|
+
columnName: column
|
|
2086
|
+
},
|
|
2087
|
+
body: file,
|
|
2088
|
+
...this.extraProps
|
|
2089
|
+
});
|
|
2090
|
+
}
|
|
2091
|
+
deleteFile({
|
|
2092
|
+
workspace,
|
|
2093
|
+
region,
|
|
2094
|
+
database,
|
|
2095
|
+
branch,
|
|
2096
|
+
table,
|
|
2097
|
+
record,
|
|
2098
|
+
column
|
|
2099
|
+
}) {
|
|
2100
|
+
return operationsByTag.files.deleteFile({
|
|
2101
|
+
pathParams: {
|
|
2102
|
+
workspace,
|
|
2103
|
+
region,
|
|
2104
|
+
dbBranchName: `${database}:${branch}`,
|
|
2105
|
+
tableName: table,
|
|
2106
|
+
recordId: record,
|
|
2107
|
+
columnName: column
|
|
2108
|
+
},
|
|
2109
|
+
...this.extraProps
|
|
2110
|
+
});
|
|
2111
|
+
}
|
|
2112
|
+
fileAccess({
|
|
2113
|
+
workspace,
|
|
2114
|
+
region,
|
|
2115
|
+
fileId,
|
|
2116
|
+
verify
|
|
2117
|
+
}) {
|
|
2118
|
+
return operationsByTag.files.fileAccess({
|
|
2119
|
+
pathParams: {
|
|
2120
|
+
workspace,
|
|
2121
|
+
region,
|
|
2122
|
+
fileId
|
|
2123
|
+
},
|
|
2124
|
+
queryParams: { verify },
|
|
2125
|
+
...this.extraProps
|
|
2126
|
+
});
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
1815
2129
|
class SearchAndFilterApi {
|
|
1816
2130
|
constructor(extraProps) {
|
|
1817
2131
|
this.extraProps = extraProps;
|
|
@@ -1903,6 +2217,21 @@ class SearchAndFilterApi {
|
|
|
1903
2217
|
...this.extraProps
|
|
1904
2218
|
});
|
|
1905
2219
|
}
|
|
2220
|
+
askTableSession({
|
|
2221
|
+
workspace,
|
|
2222
|
+
region,
|
|
2223
|
+
database,
|
|
2224
|
+
branch,
|
|
2225
|
+
table,
|
|
2226
|
+
sessionId,
|
|
2227
|
+
message
|
|
2228
|
+
}) {
|
|
2229
|
+
return operationsByTag.searchAndFilter.askTableSession({
|
|
2230
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
|
2231
|
+
body: { message },
|
|
2232
|
+
...this.extraProps
|
|
2233
|
+
});
|
|
2234
|
+
}
|
|
1906
2235
|
summarizeTable({
|
|
1907
2236
|
workspace,
|
|
1908
2237
|
region,
|
|
@@ -2194,11 +2523,13 @@ class DatabaseApi {
|
|
|
2194
2523
|
createDatabase({
|
|
2195
2524
|
workspace,
|
|
2196
2525
|
database,
|
|
2197
|
-
data
|
|
2526
|
+
data,
|
|
2527
|
+
headers
|
|
2198
2528
|
}) {
|
|
2199
2529
|
return operationsByTag.databases.createDatabase({
|
|
2200
2530
|
pathParams: { workspaceId: workspace, dbName: database },
|
|
2201
2531
|
body: data,
|
|
2532
|
+
headers,
|
|
2202
2533
|
...this.extraProps
|
|
2203
2534
|
});
|
|
2204
2535
|
}
|
|
@@ -2231,6 +2562,17 @@ class DatabaseApi {
|
|
|
2231
2562
|
...this.extraProps
|
|
2232
2563
|
});
|
|
2233
2564
|
}
|
|
2565
|
+
renameDatabase({
|
|
2566
|
+
workspace,
|
|
2567
|
+
database,
|
|
2568
|
+
newName
|
|
2569
|
+
}) {
|
|
2570
|
+
return operationsByTag.databases.renameDatabase({
|
|
2571
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
|
2572
|
+
body: { newName },
|
|
2573
|
+
...this.extraProps
|
|
2574
|
+
});
|
|
2575
|
+
}
|
|
2234
2576
|
getDatabaseGithubSettings({
|
|
2235
2577
|
workspace,
|
|
2236
2578
|
database
|
|
@@ -2277,11 +2619,261 @@ class XataApiPlugin {
|
|
|
2277
2619
|
class XataPlugin {
|
|
2278
2620
|
}
|
|
2279
2621
|
|
|
2622
|
+
class FilesPlugin extends XataPlugin {
|
|
2623
|
+
build(pluginOptions) {
|
|
2624
|
+
return {
|
|
2625
|
+
download: async (location) => {
|
|
2626
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
|
2627
|
+
return await getFileItem({
|
|
2628
|
+
pathParams: {
|
|
2629
|
+
workspace: "{workspaceId}",
|
|
2630
|
+
dbBranchName: "{dbBranch}",
|
|
2631
|
+
region: "{region}",
|
|
2632
|
+
tableName: table ?? "",
|
|
2633
|
+
recordId: record ?? "",
|
|
2634
|
+
columnName: column ?? "",
|
|
2635
|
+
fileId
|
|
2636
|
+
},
|
|
2637
|
+
...pluginOptions,
|
|
2638
|
+
rawResponse: true
|
|
2639
|
+
});
|
|
2640
|
+
},
|
|
2641
|
+
upload: async (location, file, options) => {
|
|
2642
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
|
2643
|
+
const contentType = options?.mediaType || getContentType(file);
|
|
2644
|
+
return await putFileItem({
|
|
2645
|
+
...pluginOptions,
|
|
2646
|
+
pathParams: {
|
|
2647
|
+
workspace: "{workspaceId}",
|
|
2648
|
+
dbBranchName: "{dbBranch}",
|
|
2649
|
+
region: "{region}",
|
|
2650
|
+
tableName: table ?? "",
|
|
2651
|
+
recordId: record ?? "",
|
|
2652
|
+
columnName: column ?? "",
|
|
2653
|
+
fileId
|
|
2654
|
+
},
|
|
2655
|
+
body: file,
|
|
2656
|
+
headers: { "Content-Type": contentType }
|
|
2657
|
+
});
|
|
2658
|
+
},
|
|
2659
|
+
delete: async (location) => {
|
|
2660
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
|
2661
|
+
return await deleteFileItem({
|
|
2662
|
+
pathParams: {
|
|
2663
|
+
workspace: "{workspaceId}",
|
|
2664
|
+
dbBranchName: "{dbBranch}",
|
|
2665
|
+
region: "{region}",
|
|
2666
|
+
tableName: table ?? "",
|
|
2667
|
+
recordId: record ?? "",
|
|
2668
|
+
columnName: column ?? "",
|
|
2669
|
+
fileId
|
|
2670
|
+
},
|
|
2671
|
+
...pluginOptions
|
|
2672
|
+
});
|
|
2673
|
+
}
|
|
2674
|
+
};
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
function getContentType(file) {
|
|
2678
|
+
if (typeof file === "string") {
|
|
2679
|
+
return "text/plain";
|
|
2680
|
+
}
|
|
2681
|
+
if (isBlob(file)) {
|
|
2682
|
+
return file.type;
|
|
2683
|
+
}
|
|
2684
|
+
try {
|
|
2685
|
+
return file.type;
|
|
2686
|
+
} catch (e) {
|
|
2687
|
+
}
|
|
2688
|
+
return "application/octet-stream";
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2691
|
+
function buildTransformString(transformations) {
|
|
2692
|
+
return transformations.flatMap(
|
|
2693
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
|
2694
|
+
if (key === "trim") {
|
|
2695
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
|
2696
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
|
2697
|
+
}
|
|
2698
|
+
if (key === "gravity" && typeof value === "object") {
|
|
2699
|
+
const { x = 0.5, y = 0.5 } = value;
|
|
2700
|
+
return `${key}=${[x, y].join("x")}`;
|
|
2701
|
+
}
|
|
2702
|
+
return `${key}=${value}`;
|
|
2703
|
+
})
|
|
2704
|
+
).join(",");
|
|
2705
|
+
}
|
|
2706
|
+
function transformImage(url, ...transformations) {
|
|
2707
|
+
if (!isDefined(url))
|
|
2708
|
+
return void 0;
|
|
2709
|
+
const newTransformations = buildTransformString(transformations);
|
|
2710
|
+
const { hostname, pathname, search } = new URL(url);
|
|
2711
|
+
const pathParts = pathname.split("/");
|
|
2712
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
|
2713
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
|
2714
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
|
2715
|
+
const path = pathParts.join("/");
|
|
2716
|
+
return `https://${hostname}${transform}${path}${search}`;
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
class XataFile {
|
|
2720
|
+
constructor(file) {
|
|
2721
|
+
this.id = file.id;
|
|
2722
|
+
this.name = file.name || "";
|
|
2723
|
+
this.mediaType = file.mediaType || "application/octet-stream";
|
|
2724
|
+
this.base64Content = file.base64Content;
|
|
2725
|
+
this.enablePublicUrl = file.enablePublicUrl ?? false;
|
|
2726
|
+
this.signedUrlTimeout = file.signedUrlTimeout ?? 300;
|
|
2727
|
+
this.size = file.size ?? 0;
|
|
2728
|
+
this.version = file.version ?? 1;
|
|
2729
|
+
this.url = file.url || "";
|
|
2730
|
+
this.signedUrl = file.signedUrl;
|
|
2731
|
+
this.attributes = file.attributes || {};
|
|
2732
|
+
}
|
|
2733
|
+
static fromBuffer(buffer, options = {}) {
|
|
2734
|
+
const base64Content = buffer.toString("base64");
|
|
2735
|
+
return new XataFile({ ...options, base64Content });
|
|
2736
|
+
}
|
|
2737
|
+
toBuffer() {
|
|
2738
|
+
if (!this.base64Content) {
|
|
2739
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
|
2740
|
+
}
|
|
2741
|
+
return Buffer.from(this.base64Content, "base64");
|
|
2742
|
+
}
|
|
2743
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
|
2744
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
|
2745
|
+
return this.fromUint8Array(uint8Array, options);
|
|
2746
|
+
}
|
|
2747
|
+
toArrayBuffer() {
|
|
2748
|
+
if (!this.base64Content) {
|
|
2749
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
|
2750
|
+
}
|
|
2751
|
+
const binary = atob(this.base64Content);
|
|
2752
|
+
return new ArrayBuffer(binary.length);
|
|
2753
|
+
}
|
|
2754
|
+
static fromUint8Array(uint8Array, options = {}) {
|
|
2755
|
+
let binary = "";
|
|
2756
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
|
2757
|
+
binary += String.fromCharCode(uint8Array[i]);
|
|
2758
|
+
}
|
|
2759
|
+
const base64Content = btoa(binary);
|
|
2760
|
+
return new XataFile({ ...options, base64Content });
|
|
2761
|
+
}
|
|
2762
|
+
toUint8Array() {
|
|
2763
|
+
if (!this.base64Content) {
|
|
2764
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
|
2765
|
+
}
|
|
2766
|
+
const binary = atob(this.base64Content);
|
|
2767
|
+
const uint8Array = new Uint8Array(binary.length);
|
|
2768
|
+
for (let i = 0; i < binary.length; i++) {
|
|
2769
|
+
uint8Array[i] = binary.charCodeAt(i);
|
|
2770
|
+
}
|
|
2771
|
+
return uint8Array;
|
|
2772
|
+
}
|
|
2773
|
+
static async fromBlob(file, options = {}) {
|
|
2774
|
+
const name = options.name ?? file.name;
|
|
2775
|
+
const mediaType = file.type;
|
|
2776
|
+
const arrayBuffer = await file.arrayBuffer();
|
|
2777
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
|
2778
|
+
}
|
|
2779
|
+
toBlob() {
|
|
2780
|
+
if (!this.base64Content) {
|
|
2781
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
|
2782
|
+
}
|
|
2783
|
+
const binary = atob(this.base64Content);
|
|
2784
|
+
const uint8Array = new Uint8Array(binary.length);
|
|
2785
|
+
for (let i = 0; i < binary.length; i++) {
|
|
2786
|
+
uint8Array[i] = binary.charCodeAt(i);
|
|
2787
|
+
}
|
|
2788
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
|
2789
|
+
}
|
|
2790
|
+
static fromString(string, options = {}) {
|
|
2791
|
+
const base64Content = btoa(string);
|
|
2792
|
+
return new XataFile({ ...options, base64Content });
|
|
2793
|
+
}
|
|
2794
|
+
toString() {
|
|
2795
|
+
if (!this.base64Content) {
|
|
2796
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
|
2797
|
+
}
|
|
2798
|
+
return atob(this.base64Content);
|
|
2799
|
+
}
|
|
2800
|
+
static fromBase64(base64Content, options = {}) {
|
|
2801
|
+
return new XataFile({ ...options, base64Content });
|
|
2802
|
+
}
|
|
2803
|
+
toBase64() {
|
|
2804
|
+
if (!this.base64Content) {
|
|
2805
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
|
2806
|
+
}
|
|
2807
|
+
return this.base64Content;
|
|
2808
|
+
}
|
|
2809
|
+
transform(...options) {
|
|
2810
|
+
return {
|
|
2811
|
+
url: transformImage(this.url, ...options),
|
|
2812
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
|
2813
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
|
2814
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
|
2815
|
+
};
|
|
2816
|
+
}
|
|
2817
|
+
}
|
|
2818
|
+
const parseInputFileEntry = async (entry) => {
|
|
2819
|
+
if (!isDefined(entry))
|
|
2820
|
+
return null;
|
|
2821
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
|
2822
|
+
return compactObject({
|
|
2823
|
+
id,
|
|
2824
|
+
// Name cannot be an empty string in our API
|
|
2825
|
+
name: name ? name : void 0,
|
|
2826
|
+
mediaType,
|
|
2827
|
+
base64Content,
|
|
2828
|
+
enablePublicUrl,
|
|
2829
|
+
signedUrlTimeout
|
|
2830
|
+
});
|
|
2831
|
+
};
|
|
2832
|
+
|
|
2280
2833
|
function cleanFilter(filter) {
|
|
2281
|
-
if (!filter)
|
|
2834
|
+
if (!isDefined(filter))
|
|
2282
2835
|
return void 0;
|
|
2283
|
-
|
|
2284
|
-
|
|
2836
|
+
if (!isObject(filter))
|
|
2837
|
+
return filter;
|
|
2838
|
+
const values = Object.fromEntries(
|
|
2839
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
|
2840
|
+
if (!isDefined(value))
|
|
2841
|
+
return acc;
|
|
2842
|
+
if (Array.isArray(value)) {
|
|
2843
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
|
2844
|
+
if (clean.length === 0)
|
|
2845
|
+
return acc;
|
|
2846
|
+
return [...acc, [key, clean]];
|
|
2847
|
+
}
|
|
2848
|
+
if (isObject(value)) {
|
|
2849
|
+
const clean = cleanFilter(value);
|
|
2850
|
+
if (!isDefined(clean))
|
|
2851
|
+
return acc;
|
|
2852
|
+
return [...acc, [key, clean]];
|
|
2853
|
+
}
|
|
2854
|
+
return [...acc, [key, value]];
|
|
2855
|
+
}, [])
|
|
2856
|
+
);
|
|
2857
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
function stringifyJson(value) {
|
|
2861
|
+
if (!isDefined(value))
|
|
2862
|
+
return value;
|
|
2863
|
+
if (isString(value))
|
|
2864
|
+
return value;
|
|
2865
|
+
try {
|
|
2866
|
+
return JSON.stringify(value);
|
|
2867
|
+
} catch (e) {
|
|
2868
|
+
return value;
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
function parseJson(value) {
|
|
2872
|
+
try {
|
|
2873
|
+
return JSON.parse(value);
|
|
2874
|
+
} catch (e) {
|
|
2875
|
+
return value;
|
|
2876
|
+
}
|
|
2285
2877
|
}
|
|
2286
2878
|
|
|
2287
2879
|
var __accessCheck$6 = (obj, member, msg) => {
|
|
@@ -2310,31 +2902,59 @@ class Page {
|
|
|
2310
2902
|
this.meta = meta;
|
|
2311
2903
|
this.records = new RecordArray(this, records);
|
|
2312
2904
|
}
|
|
2905
|
+
/**
|
|
2906
|
+
* Retrieves the next page of results.
|
|
2907
|
+
* @param size Maximum number of results to be retrieved.
|
|
2908
|
+
* @param offset Number of results to skip when retrieving the results.
|
|
2909
|
+
* @returns The next page or results.
|
|
2910
|
+
*/
|
|
2313
2911
|
async nextPage(size, offset) {
|
|
2314
2912
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
|
2315
2913
|
}
|
|
2914
|
+
/**
|
|
2915
|
+
* Retrieves the previous page of results.
|
|
2916
|
+
* @param size Maximum number of results to be retrieved.
|
|
2917
|
+
* @param offset Number of results to skip when retrieving the results.
|
|
2918
|
+
* @returns The previous page or results.
|
|
2919
|
+
*/
|
|
2316
2920
|
async previousPage(size, offset) {
|
|
2317
2921
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
|
2318
2922
|
}
|
|
2923
|
+
/**
|
|
2924
|
+
* Retrieves the start page of results.
|
|
2925
|
+
* @param size Maximum number of results to be retrieved.
|
|
2926
|
+
* @param offset Number of results to skip when retrieving the results.
|
|
2927
|
+
* @returns The start page or results.
|
|
2928
|
+
*/
|
|
2319
2929
|
async startPage(size, offset) {
|
|
2320
2930
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
|
2321
2931
|
}
|
|
2932
|
+
/**
|
|
2933
|
+
* Retrieves the end page of results.
|
|
2934
|
+
* @param size Maximum number of results to be retrieved.
|
|
2935
|
+
* @param offset Number of results to skip when retrieving the results.
|
|
2936
|
+
* @returns The end page or results.
|
|
2937
|
+
*/
|
|
2322
2938
|
async endPage(size, offset) {
|
|
2323
2939
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
|
2324
2940
|
}
|
|
2941
|
+
/**
|
|
2942
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
|
2943
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
|
2944
|
+
*/
|
|
2325
2945
|
hasNextPage() {
|
|
2326
2946
|
return this.meta.page.more;
|
|
2327
2947
|
}
|
|
2328
2948
|
}
|
|
2329
2949
|
_query = new WeakMap();
|
|
2330
|
-
const PAGINATION_MAX_SIZE =
|
|
2950
|
+
const PAGINATION_MAX_SIZE = 1e3;
|
|
2331
2951
|
const PAGINATION_DEFAULT_SIZE = 20;
|
|
2332
|
-
const PAGINATION_MAX_OFFSET =
|
|
2952
|
+
const PAGINATION_MAX_OFFSET = 49e3;
|
|
2333
2953
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
|
2334
2954
|
function isCursorPaginationOptions(options) {
|
|
2335
2955
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
|
2336
2956
|
}
|
|
2337
|
-
const _RecordArray = class extends Array {
|
|
2957
|
+
const _RecordArray = class _RecordArray extends Array {
|
|
2338
2958
|
constructor(...args) {
|
|
2339
2959
|
super(..._RecordArray.parseConstructorParams(...args));
|
|
2340
2960
|
__privateAdd$6(this, _page, void 0);
|
|
@@ -2362,28 +2982,51 @@ const _RecordArray = class extends Array {
|
|
|
2362
2982
|
map(callbackfn, thisArg) {
|
|
2363
2983
|
return this.toArray().map(callbackfn, thisArg);
|
|
2364
2984
|
}
|
|
2985
|
+
/**
|
|
2986
|
+
* Retrieve next page of records
|
|
2987
|
+
*
|
|
2988
|
+
* @returns A new array of objects
|
|
2989
|
+
*/
|
|
2365
2990
|
async nextPage(size, offset) {
|
|
2366
2991
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
|
2367
2992
|
return new _RecordArray(newPage);
|
|
2368
2993
|
}
|
|
2994
|
+
/**
|
|
2995
|
+
* Retrieve previous page of records
|
|
2996
|
+
*
|
|
2997
|
+
* @returns A new array of objects
|
|
2998
|
+
*/
|
|
2369
2999
|
async previousPage(size, offset) {
|
|
2370
3000
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
|
2371
3001
|
return new _RecordArray(newPage);
|
|
2372
3002
|
}
|
|
3003
|
+
/**
|
|
3004
|
+
* Retrieve start page of records
|
|
3005
|
+
*
|
|
3006
|
+
* @returns A new array of objects
|
|
3007
|
+
*/
|
|
2373
3008
|
async startPage(size, offset) {
|
|
2374
3009
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
|
2375
3010
|
return new _RecordArray(newPage);
|
|
2376
3011
|
}
|
|
3012
|
+
/**
|
|
3013
|
+
* Retrieve end page of records
|
|
3014
|
+
*
|
|
3015
|
+
* @returns A new array of objects
|
|
3016
|
+
*/
|
|
2377
3017
|
async endPage(size, offset) {
|
|
2378
3018
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
|
2379
3019
|
return new _RecordArray(newPage);
|
|
2380
3020
|
}
|
|
3021
|
+
/**
|
|
3022
|
+
* @returns Boolean indicating if there is a next page
|
|
3023
|
+
*/
|
|
2381
3024
|
hasNextPage() {
|
|
2382
3025
|
return __privateGet$6(this, _page).meta.page.more;
|
|
2383
3026
|
}
|
|
2384
3027
|
};
|
|
2385
|
-
let RecordArray = _RecordArray;
|
|
2386
3028
|
_page = new WeakMap();
|
|
3029
|
+
let RecordArray = _RecordArray;
|
|
2387
3030
|
|
|
2388
3031
|
var __accessCheck$5 = (obj, member, msg) => {
|
|
2389
3032
|
if (!member.has(obj))
|
|
@@ -2408,13 +3051,14 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
|
2408
3051
|
return method;
|
|
2409
3052
|
};
|
|
2410
3053
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
|
2411
|
-
const _Query = class {
|
|
3054
|
+
const _Query = class _Query {
|
|
2412
3055
|
constructor(repository, table, data, rawParent) {
|
|
2413
3056
|
__privateAdd$5(this, _cleanFilterConstraint);
|
|
2414
3057
|
__privateAdd$5(this, _table$1, void 0);
|
|
2415
3058
|
__privateAdd$5(this, _repository, void 0);
|
|
2416
3059
|
__privateAdd$5(this, _data, { filter: {} });
|
|
2417
|
-
|
|
3060
|
+
// Implements pagination
|
|
3061
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
|
2418
3062
|
this.records = new RecordArray(this, []);
|
|
2419
3063
|
__privateSet$5(this, _table$1, table);
|
|
2420
3064
|
if (repository) {
|
|
@@ -2451,18 +3095,38 @@ const _Query = class {
|
|
|
2451
3095
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
|
2452
3096
|
return toBase64(key);
|
|
2453
3097
|
}
|
|
3098
|
+
/**
|
|
3099
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
|
3100
|
+
* @param queries An array of subqueries.
|
|
3101
|
+
* @returns A new Query object.
|
|
3102
|
+
*/
|
|
2454
3103
|
any(...queries) {
|
|
2455
3104
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
|
2456
3105
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
|
2457
3106
|
}
|
|
3107
|
+
/**
|
|
3108
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
|
3109
|
+
* @param queries An array of subqueries.
|
|
3110
|
+
* @returns A new Query object.
|
|
3111
|
+
*/
|
|
2458
3112
|
all(...queries) {
|
|
2459
3113
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
|
2460
3114
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
|
2461
3115
|
}
|
|
3116
|
+
/**
|
|
3117
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
|
3118
|
+
* @param queries An array of subqueries.
|
|
3119
|
+
* @returns A new Query object.
|
|
3120
|
+
*/
|
|
2462
3121
|
not(...queries) {
|
|
2463
3122
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
|
2464
3123
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
|
2465
3124
|
}
|
|
3125
|
+
/**
|
|
3126
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
|
3127
|
+
* @param queries An array of subqueries.
|
|
3128
|
+
* @returns A new Query object.
|
|
3129
|
+
*/
|
|
2466
3130
|
none(...queries) {
|
|
2467
3131
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
|
2468
3132
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
|
@@ -2485,6 +3149,11 @@ const _Query = class {
|
|
|
2485
3149
|
const sort = [...originalSort, { column, direction }];
|
|
2486
3150
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
|
2487
3151
|
}
|
|
3152
|
+
/**
|
|
3153
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
|
3154
|
+
* @param columns Array of column names to be returned by the query.
|
|
3155
|
+
* @returns A new Query object.
|
|
3156
|
+
*/
|
|
2488
3157
|
select(columns) {
|
|
2489
3158
|
return new _Query(
|
|
2490
3159
|
__privateGet$5(this, _repository),
|
|
@@ -2497,6 +3166,12 @@ const _Query = class {
|
|
|
2497
3166
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
|
2498
3167
|
return __privateGet$5(this, _repository).query(query);
|
|
2499
3168
|
}
|
|
3169
|
+
/**
|
|
3170
|
+
* Get results in an iterator
|
|
3171
|
+
*
|
|
3172
|
+
* @async
|
|
3173
|
+
* @returns Async interable of results
|
|
3174
|
+
*/
|
|
2500
3175
|
async *[Symbol.asyncIterator]() {
|
|
2501
3176
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
|
2502
3177
|
yield record;
|
|
@@ -2557,26 +3232,53 @@ const _Query = class {
|
|
|
2557
3232
|
);
|
|
2558
3233
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
|
2559
3234
|
}
|
|
3235
|
+
/**
|
|
3236
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
|
3237
|
+
* @param ttl The cache TTL in milliseconds.
|
|
3238
|
+
* @returns A new Query object.
|
|
3239
|
+
*/
|
|
2560
3240
|
cache(ttl) {
|
|
2561
3241
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
|
2562
3242
|
}
|
|
3243
|
+
/**
|
|
3244
|
+
* Retrieve next page of records
|
|
3245
|
+
*
|
|
3246
|
+
* @returns A new page object.
|
|
3247
|
+
*/
|
|
2563
3248
|
nextPage(size, offset) {
|
|
2564
3249
|
return this.startPage(size, offset);
|
|
2565
3250
|
}
|
|
3251
|
+
/**
|
|
3252
|
+
* Retrieve previous page of records
|
|
3253
|
+
*
|
|
3254
|
+
* @returns A new page object
|
|
3255
|
+
*/
|
|
2566
3256
|
previousPage(size, offset) {
|
|
2567
3257
|
return this.startPage(size, offset);
|
|
2568
3258
|
}
|
|
3259
|
+
/**
|
|
3260
|
+
* Retrieve start page of records
|
|
3261
|
+
*
|
|
3262
|
+
* @returns A new page object
|
|
3263
|
+
*/
|
|
2569
3264
|
startPage(size, offset) {
|
|
2570
3265
|
return this.getPaginated({ pagination: { size, offset } });
|
|
2571
3266
|
}
|
|
3267
|
+
/**
|
|
3268
|
+
* Retrieve last page of records
|
|
3269
|
+
*
|
|
3270
|
+
* @returns A new page object
|
|
3271
|
+
*/
|
|
2572
3272
|
endPage(size, offset) {
|
|
2573
3273
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
|
2574
3274
|
}
|
|
3275
|
+
/**
|
|
3276
|
+
* @returns Boolean indicating if there is a next page
|
|
3277
|
+
*/
|
|
2575
3278
|
hasNextPage() {
|
|
2576
3279
|
return this.meta.page.more;
|
|
2577
3280
|
}
|
|
2578
3281
|
};
|
|
2579
|
-
let Query = _Query;
|
|
2580
3282
|
_table$1 = new WeakMap();
|
|
2581
3283
|
_repository = new WeakMap();
|
|
2582
3284
|
_data = new WeakMap();
|
|
@@ -2591,6 +3293,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
|
2591
3293
|
}
|
|
2592
3294
|
return value;
|
|
2593
3295
|
};
|
|
3296
|
+
let Query = _Query;
|
|
2594
3297
|
function cleanParent(data, parent) {
|
|
2595
3298
|
if (isCursorPaginationOptions(data.pagination)) {
|
|
2596
3299
|
return { ...parent, sort: void 0, filter: void 0 };
|
|
@@ -2598,6 +3301,22 @@ function cleanParent(data, parent) {
|
|
|
2598
3301
|
return parent;
|
|
2599
3302
|
}
|
|
2600
3303
|
|
|
3304
|
+
const RecordColumnTypes = [
|
|
3305
|
+
"bool",
|
|
3306
|
+
"int",
|
|
3307
|
+
"float",
|
|
3308
|
+
"string",
|
|
3309
|
+
"text",
|
|
3310
|
+
"email",
|
|
3311
|
+
"multiple",
|
|
3312
|
+
"link",
|
|
3313
|
+
"object",
|
|
3314
|
+
"datetime",
|
|
3315
|
+
"vector",
|
|
3316
|
+
"file[]",
|
|
3317
|
+
"file",
|
|
3318
|
+
"json"
|
|
3319
|
+
];
|
|
2601
3320
|
function isIdentifiable(x) {
|
|
2602
3321
|
return isObject(x) && isString(x?.id);
|
|
2603
3322
|
}
|
|
@@ -2607,11 +3326,33 @@ function isXataRecord(x) {
|
|
|
2607
3326
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
|
2608
3327
|
}
|
|
2609
3328
|
|
|
3329
|
+
function isValidExpandedColumn(column) {
|
|
3330
|
+
return isObject(column) && isString(column.name);
|
|
3331
|
+
}
|
|
3332
|
+
function isValidSelectableColumns(columns) {
|
|
3333
|
+
if (!Array.isArray(columns)) {
|
|
3334
|
+
return false;
|
|
3335
|
+
}
|
|
3336
|
+
return columns.every((column) => {
|
|
3337
|
+
if (typeof column === "string") {
|
|
3338
|
+
return true;
|
|
3339
|
+
}
|
|
3340
|
+
if (typeof column === "object") {
|
|
3341
|
+
return isValidExpandedColumn(column);
|
|
3342
|
+
}
|
|
3343
|
+
return false;
|
|
3344
|
+
});
|
|
3345
|
+
}
|
|
3346
|
+
|
|
2610
3347
|
function isSortFilterString(value) {
|
|
2611
3348
|
return isString(value);
|
|
2612
3349
|
}
|
|
2613
3350
|
function isSortFilterBase(filter) {
|
|
2614
|
-
return isObject(filter) && Object.
|
|
3351
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
|
3352
|
+
if (key === "*")
|
|
3353
|
+
return value === "random";
|
|
3354
|
+
return value === "asc" || value === "desc";
|
|
3355
|
+
});
|
|
2615
3356
|
}
|
|
2616
3357
|
function isSortFilterObject(filter) {
|
|
2617
3358
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
|
@@ -2652,7 +3393,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
|
2652
3393
|
__accessCheck$4(obj, member, "access private method");
|
|
2653
3394
|
return method;
|
|
2654
3395
|
};
|
|
2655
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _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$1, getSchemaTables_fn$1;
|
|
3396
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _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$1, getSchemaTables_fn$1, _transformObjectToApi, transformObjectToApi_fn;
|
|
2656
3397
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
|
2657
3398
|
class Repository extends Query {
|
|
2658
3399
|
}
|
|
@@ -2674,6 +3415,7 @@ class RestRepository extends Query {
|
|
|
2674
3415
|
__privateAdd$4(this, _setCacheQuery);
|
|
2675
3416
|
__privateAdd$4(this, _getCacheQuery);
|
|
2676
3417
|
__privateAdd$4(this, _getSchemaTables$1);
|
|
3418
|
+
__privateAdd$4(this, _transformObjectToApi);
|
|
2677
3419
|
__privateAdd$4(this, _table, void 0);
|
|
2678
3420
|
__privateAdd$4(this, _getFetchProps, void 0);
|
|
2679
3421
|
__privateAdd$4(this, _db, void 0);
|
|
@@ -2702,24 +3444,24 @@ class RestRepository extends Query {
|
|
|
2702
3444
|
if (a.length === 0)
|
|
2703
3445
|
return [];
|
|
2704
3446
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
|
2705
|
-
const columns =
|
|
3447
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
|
2706
3448
|
const result = await this.read(ids, columns);
|
|
2707
3449
|
return result;
|
|
2708
3450
|
}
|
|
2709
3451
|
if (isString(a) && isObject(b)) {
|
|
2710
3452
|
if (a === "")
|
|
2711
3453
|
throw new Error("The id can't be empty");
|
|
2712
|
-
const columns =
|
|
3454
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
|
2713
3455
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
|
2714
3456
|
}
|
|
2715
3457
|
if (isObject(a) && isString(a.id)) {
|
|
2716
3458
|
if (a.id === "")
|
|
2717
3459
|
throw new Error("The id can't be empty");
|
|
2718
|
-
const columns =
|
|
3460
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
|
2719
3461
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
|
2720
3462
|
}
|
|
2721
3463
|
if (isObject(a)) {
|
|
2722
|
-
const columns =
|
|
3464
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
|
2723
3465
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
|
2724
3466
|
}
|
|
2725
3467
|
throw new Error("Invalid arguments for create method");
|
|
@@ -2727,7 +3469,7 @@ class RestRepository extends Query {
|
|
|
2727
3469
|
}
|
|
2728
3470
|
async read(a, b) {
|
|
2729
3471
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
|
2730
|
-
const columns =
|
|
3472
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
|
2731
3473
|
if (Array.isArray(a)) {
|
|
2732
3474
|
if (a.length === 0)
|
|
2733
3475
|
return [];
|
|
@@ -2754,7 +3496,13 @@ class RestRepository extends Query {
|
|
|
2754
3496
|
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2755
3497
|
});
|
|
2756
3498
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2757
|
-
return initObject(
|
|
3499
|
+
return initObject(
|
|
3500
|
+
__privateGet$4(this, _db),
|
|
3501
|
+
schemaTables,
|
|
3502
|
+
__privateGet$4(this, _table),
|
|
3503
|
+
response,
|
|
3504
|
+
columns
|
|
3505
|
+
);
|
|
2758
3506
|
} catch (e) {
|
|
2759
3507
|
if (isObject(e) && e.status === 404) {
|
|
2760
3508
|
return null;
|
|
@@ -2796,17 +3544,17 @@ class RestRepository extends Query {
|
|
|
2796
3544
|
ifVersion,
|
|
2797
3545
|
upsert: false
|
|
2798
3546
|
});
|
|
2799
|
-
const columns =
|
|
3547
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
|
2800
3548
|
const result = await this.read(a, columns);
|
|
2801
3549
|
return result;
|
|
2802
3550
|
}
|
|
2803
3551
|
try {
|
|
2804
3552
|
if (isString(a) && isObject(b)) {
|
|
2805
|
-
const columns =
|
|
3553
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
|
2806
3554
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
|
2807
3555
|
}
|
|
2808
3556
|
if (isObject(a) && isString(a.id)) {
|
|
2809
|
-
const columns =
|
|
3557
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
|
2810
3558
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
|
2811
3559
|
}
|
|
2812
3560
|
} catch (error) {
|
|
@@ -2846,17 +3594,27 @@ class RestRepository extends Query {
|
|
|
2846
3594
|
ifVersion,
|
|
2847
3595
|
upsert: true
|
|
2848
3596
|
});
|
|
2849
|
-
const columns =
|
|
3597
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
|
2850
3598
|
const result = await this.read(a, columns);
|
|
2851
3599
|
return result;
|
|
2852
3600
|
}
|
|
2853
3601
|
if (isString(a) && isObject(b)) {
|
|
2854
|
-
|
|
2855
|
-
|
|
3602
|
+
if (a === "")
|
|
3603
|
+
throw new Error("The id can't be empty");
|
|
3604
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
|
3605
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
|
2856
3606
|
}
|
|
2857
3607
|
if (isObject(a) && isString(a.id)) {
|
|
2858
|
-
|
|
2859
|
-
|
|
3608
|
+
if (a.id === "")
|
|
3609
|
+
throw new Error("The id can't be empty");
|
|
3610
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
|
3611
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
|
3612
|
+
}
|
|
3613
|
+
if (!isDefined(a) && isObject(b)) {
|
|
3614
|
+
return await this.create(b, c);
|
|
3615
|
+
}
|
|
3616
|
+
if (isObject(a) && !isDefined(a.id)) {
|
|
3617
|
+
return await this.create(a, b);
|
|
2860
3618
|
}
|
|
2861
3619
|
throw new Error("Invalid arguments for createOrUpdate method");
|
|
2862
3620
|
});
|
|
@@ -2868,17 +3626,27 @@ class RestRepository extends Query {
|
|
|
2868
3626
|
if (a.length === 0)
|
|
2869
3627
|
return [];
|
|
2870
3628
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
|
2871
|
-
const columns =
|
|
3629
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
|
2872
3630
|
const result = await this.read(ids, columns);
|
|
2873
3631
|
return result;
|
|
2874
3632
|
}
|
|
2875
3633
|
if (isString(a) && isObject(b)) {
|
|
2876
|
-
|
|
2877
|
-
|
|
3634
|
+
if (a === "")
|
|
3635
|
+
throw new Error("The id can't be empty");
|
|
3636
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
|
3637
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
|
2878
3638
|
}
|
|
2879
3639
|
if (isObject(a) && isString(a.id)) {
|
|
2880
|
-
|
|
2881
|
-
|
|
3640
|
+
if (a.id === "")
|
|
3641
|
+
throw new Error("The id can't be empty");
|
|
3642
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
|
3643
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
|
3644
|
+
}
|
|
3645
|
+
if (!isDefined(a) && isObject(b)) {
|
|
3646
|
+
return await this.create(b, c);
|
|
3647
|
+
}
|
|
3648
|
+
if (isObject(a) && !isDefined(a.id)) {
|
|
3649
|
+
return await this.create(a, b);
|
|
2882
3650
|
}
|
|
2883
3651
|
throw new Error("Invalid arguments for createOrReplace method");
|
|
2884
3652
|
});
|
|
@@ -2895,7 +3663,7 @@ class RestRepository extends Query {
|
|
|
2895
3663
|
return o.id;
|
|
2896
3664
|
throw new Error("Invalid arguments for delete method");
|
|
2897
3665
|
});
|
|
2898
|
-
const columns =
|
|
3666
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
|
2899
3667
|
const result = await this.read(a, columns);
|
|
2900
3668
|
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
|
2901
3669
|
return result;
|
|
@@ -3014,7 +3782,13 @@ class RestRepository extends Query {
|
|
|
3014
3782
|
});
|
|
3015
3783
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
3016
3784
|
const records = objects.map(
|
|
3017
|
-
(record) => initObject(
|
|
3785
|
+
(record) => initObject(
|
|
3786
|
+
__privateGet$4(this, _db),
|
|
3787
|
+
schemaTables,
|
|
3788
|
+
__privateGet$4(this, _table),
|
|
3789
|
+
record,
|
|
3790
|
+
data.columns ?? ["*"]
|
|
3791
|
+
)
|
|
3018
3792
|
);
|
|
3019
3793
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
|
3020
3794
|
return new Page(query, meta, records);
|
|
@@ -3045,23 +3819,28 @@ class RestRepository extends Query {
|
|
|
3045
3819
|
});
|
|
3046
3820
|
}
|
|
3047
3821
|
ask(question, options) {
|
|
3822
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
|
3048
3823
|
const params = {
|
|
3049
3824
|
pathParams: {
|
|
3050
3825
|
workspace: "{workspaceId}",
|
|
3051
3826
|
dbBranchName: "{dbBranch}",
|
|
3052
3827
|
region: "{region}",
|
|
3053
|
-
tableName: __privateGet$4(this, _table)
|
|
3828
|
+
tableName: __privateGet$4(this, _table),
|
|
3829
|
+
sessionId: options?.sessionId
|
|
3054
3830
|
},
|
|
3055
3831
|
body: {
|
|
3056
|
-
|
|
3057
|
-
|
|
3832
|
+
...questionParam,
|
|
3833
|
+
rules: options?.rules,
|
|
3834
|
+
searchType: options?.searchType,
|
|
3835
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
|
3836
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
|
3058
3837
|
},
|
|
3059
3838
|
...__privateGet$4(this, _getFetchProps).call(this)
|
|
3060
3839
|
};
|
|
3061
3840
|
if (options?.onMessage) {
|
|
3062
3841
|
fetchSSERequest({
|
|
3063
3842
|
endpoint: "dataPlane",
|
|
3064
|
-
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
|
3843
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
|
3065
3844
|
method: "POST",
|
|
3066
3845
|
onMessage: (message) => {
|
|
3067
3846
|
options.onMessage?.({ answer: message.text, records: message.records });
|
|
@@ -3069,7 +3848,7 @@ class RestRepository extends Query {
|
|
|
3069
3848
|
...params
|
|
3070
3849
|
});
|
|
3071
3850
|
} else {
|
|
3072
|
-
return
|
|
3851
|
+
return askTableSession(params);
|
|
3073
3852
|
}
|
|
3074
3853
|
}
|
|
3075
3854
|
}
|
|
@@ -3081,7 +3860,7 @@ _schemaTables$2 = new WeakMap();
|
|
|
3081
3860
|
_trace = new WeakMap();
|
|
3082
3861
|
_insertRecordWithoutId = new WeakSet();
|
|
3083
3862
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
3084
|
-
const record =
|
|
3863
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
|
3085
3864
|
const response = await insertRecord({
|
|
3086
3865
|
pathParams: {
|
|
3087
3866
|
workspace: "{workspaceId}",
|
|
@@ -3098,7 +3877,9 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
|
3098
3877
|
};
|
|
3099
3878
|
_insertRecordWithId = new WeakSet();
|
|
3100
3879
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
|
3101
|
-
|
|
3880
|
+
if (!recordId)
|
|
3881
|
+
return null;
|
|
3882
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
|
3102
3883
|
const response = await insertRecordWithID({
|
|
3103
3884
|
pathParams: {
|
|
3104
3885
|
workspace: "{workspaceId}",
|
|
@@ -3116,21 +3897,20 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
|
3116
3897
|
};
|
|
3117
3898
|
_insertRecords = new WeakSet();
|
|
3118
3899
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
3119
|
-
const
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
);
|
|
3900
|
+
const operations = await promiseMap(objects, async (object) => {
|
|
3901
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
|
3902
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
|
3903
|
+
});
|
|
3904
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
|
3125
3905
|
const ids = [];
|
|
3126
|
-
for (const
|
|
3906
|
+
for (const operations2 of chunkedOperations) {
|
|
3127
3907
|
const { results } = await branchTransaction({
|
|
3128
3908
|
pathParams: {
|
|
3129
3909
|
workspace: "{workspaceId}",
|
|
3130
3910
|
dbBranchName: "{dbBranch}",
|
|
3131
3911
|
region: "{region}"
|
|
3132
3912
|
},
|
|
3133
|
-
body: { operations },
|
|
3913
|
+
body: { operations: operations2 },
|
|
3134
3914
|
...__privateGet$4(this, _getFetchProps).call(this)
|
|
3135
3915
|
});
|
|
3136
3916
|
for (const result of results) {
|
|
@@ -3145,7 +3925,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
|
3145
3925
|
};
|
|
3146
3926
|
_updateRecordWithID = new WeakSet();
|
|
3147
3927
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
|
3148
|
-
|
|
3928
|
+
if (!recordId)
|
|
3929
|
+
return null;
|
|
3930
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
|
3149
3931
|
try {
|
|
3150
3932
|
const response = await updateRecordWithID({
|
|
3151
3933
|
pathParams: {
|
|
@@ -3170,21 +3952,20 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
|
3170
3952
|
};
|
|
3171
3953
|
_updateRecords = new WeakSet();
|
|
3172
3954
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
3173
|
-
const
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
);
|
|
3955
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
|
3956
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
|
3957
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
|
3958
|
+
});
|
|
3959
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
|
3179
3960
|
const ids = [];
|
|
3180
|
-
for (const
|
|
3961
|
+
for (const operations2 of chunkedOperations) {
|
|
3181
3962
|
const { results } = await branchTransaction({
|
|
3182
3963
|
pathParams: {
|
|
3183
3964
|
workspace: "{workspaceId}",
|
|
3184
3965
|
dbBranchName: "{dbBranch}",
|
|
3185
3966
|
region: "{region}"
|
|
3186
3967
|
},
|
|
3187
|
-
body: { operations },
|
|
3968
|
+
body: { operations: operations2 },
|
|
3188
3969
|
...__privateGet$4(this, _getFetchProps).call(this)
|
|
3189
3970
|
});
|
|
3190
3971
|
for (const result of results) {
|
|
@@ -3199,6 +3980,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
|
3199
3980
|
};
|
|
3200
3981
|
_upsertRecordWithID = new WeakSet();
|
|
3201
3982
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
|
3983
|
+
if (!recordId)
|
|
3984
|
+
return null;
|
|
3202
3985
|
const response = await upsertRecordWithID({
|
|
3203
3986
|
pathParams: {
|
|
3204
3987
|
workspace: "{workspaceId}",
|
|
@@ -3216,6 +3999,8 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
|
3216
3999
|
};
|
|
3217
4000
|
_deleteRecord = new WeakSet();
|
|
3218
4001
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
4002
|
+
if (!recordId)
|
|
4003
|
+
return null;
|
|
3219
4004
|
try {
|
|
3220
4005
|
const response = await deleteRecord({
|
|
3221
4006
|
pathParams: {
|
|
@@ -3240,7 +4025,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
|
3240
4025
|
_deleteRecords = new WeakSet();
|
|
3241
4026
|
deleteRecords_fn = async function(recordIds) {
|
|
3242
4027
|
const chunkedOperations = chunk(
|
|
3243
|
-
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
|
4028
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
|
3244
4029
|
BULK_OPERATION_MAX_SIZE
|
|
3245
4030
|
);
|
|
3246
4031
|
for (const operations of chunkedOperations) {
|
|
@@ -3257,7 +4042,7 @@ deleteRecords_fn = async function(recordIds) {
|
|
|
3257
4042
|
};
|
|
3258
4043
|
_setCacheQuery = new WeakSet();
|
|
3259
4044
|
setCacheQuery_fn = async function(query, meta, records) {
|
|
3260
|
-
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
|
4045
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
|
3261
4046
|
};
|
|
3262
4047
|
_getCacheQuery = new WeakSet();
|
|
3263
4048
|
getCacheQuery_fn = async function(query) {
|
|
@@ -3283,12 +4068,40 @@ getSchemaTables_fn$1 = async function() {
|
|
|
3283
4068
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
|
3284
4069
|
return schema.tables;
|
|
3285
4070
|
};
|
|
3286
|
-
|
|
3287
|
-
|
|
4071
|
+
_transformObjectToApi = new WeakSet();
|
|
4072
|
+
transformObjectToApi_fn = async function(object) {
|
|
4073
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
4074
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
|
4075
|
+
if (!schema)
|
|
4076
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
|
4077
|
+
const result = {};
|
|
4078
|
+
for (const [key, value] of Object.entries(object)) {
|
|
3288
4079
|
if (key === "xata")
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
4080
|
+
continue;
|
|
4081
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
|
4082
|
+
switch (type) {
|
|
4083
|
+
case "link": {
|
|
4084
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
|
4085
|
+
break;
|
|
4086
|
+
}
|
|
4087
|
+
case "datetime": {
|
|
4088
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
|
4089
|
+
break;
|
|
4090
|
+
}
|
|
4091
|
+
case `file`:
|
|
4092
|
+
result[key] = await parseInputFileEntry(value);
|
|
4093
|
+
break;
|
|
4094
|
+
case "file[]":
|
|
4095
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
|
4096
|
+
break;
|
|
4097
|
+
case "json":
|
|
4098
|
+
result[key] = stringifyJson(value);
|
|
4099
|
+
break;
|
|
4100
|
+
default:
|
|
4101
|
+
result[key] = value;
|
|
4102
|
+
}
|
|
4103
|
+
}
|
|
4104
|
+
return result;
|
|
3292
4105
|
};
|
|
3293
4106
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
3294
4107
|
const data = {};
|
|
@@ -3320,18 +4133,33 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
|
3320
4133
|
if (item === column.name) {
|
|
3321
4134
|
return [...acc, "*"];
|
|
3322
4135
|
}
|
|
3323
|
-
if (item.startsWith(`${column.name}.`)) {
|
|
4136
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
|
3324
4137
|
const [, ...path] = item.split(".");
|
|
3325
4138
|
return [...acc, path.join(".")];
|
|
3326
4139
|
}
|
|
3327
4140
|
return acc;
|
|
3328
4141
|
}, []);
|
|
3329
|
-
data[column.name] = initObject(
|
|
4142
|
+
data[column.name] = initObject(
|
|
4143
|
+
db,
|
|
4144
|
+
schemaTables,
|
|
4145
|
+
linkTable,
|
|
4146
|
+
value,
|
|
4147
|
+
selectedLinkColumns
|
|
4148
|
+
);
|
|
3330
4149
|
} else {
|
|
3331
4150
|
data[column.name] = null;
|
|
3332
4151
|
}
|
|
3333
4152
|
break;
|
|
3334
4153
|
}
|
|
4154
|
+
case "file":
|
|
4155
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
|
4156
|
+
break;
|
|
4157
|
+
case "file[]":
|
|
4158
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
|
4159
|
+
break;
|
|
4160
|
+
case "json":
|
|
4161
|
+
data[column.name] = parseJson(value);
|
|
4162
|
+
break;
|
|
3335
4163
|
default:
|
|
3336
4164
|
data[column.name] = value ?? null;
|
|
3337
4165
|
if (column.notNull === true && value === null) {
|
|
@@ -3341,30 +4169,32 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
|
3341
4169
|
}
|
|
3342
4170
|
}
|
|
3343
4171
|
const record = { ...data };
|
|
4172
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
|
3344
4173
|
record.read = function(columns2) {
|
|
3345
4174
|
return db[table].read(record["id"], columns2);
|
|
3346
4175
|
};
|
|
3347
4176
|
record.update = function(data2, b, c) {
|
|
3348
|
-
const columns2 =
|
|
4177
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
|
3349
4178
|
const ifVersion = parseIfVersion(b, c);
|
|
3350
4179
|
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
|
3351
4180
|
};
|
|
3352
4181
|
record.replace = function(data2, b, c) {
|
|
3353
|
-
const columns2 =
|
|
4182
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
|
3354
4183
|
const ifVersion = parseIfVersion(b, c);
|
|
3355
4184
|
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
|
3356
4185
|
};
|
|
3357
4186
|
record.delete = function() {
|
|
3358
4187
|
return db[table].delete(record["id"]);
|
|
3359
4188
|
};
|
|
4189
|
+
record.xata = Object.freeze(metadata);
|
|
3360
4190
|
record.getMetadata = function() {
|
|
3361
|
-
return xata;
|
|
4191
|
+
return record.xata;
|
|
3362
4192
|
};
|
|
3363
4193
|
record.toSerializable = function() {
|
|
3364
|
-
return JSON.parse(JSON.stringify(
|
|
4194
|
+
return JSON.parse(JSON.stringify(record));
|
|
3365
4195
|
};
|
|
3366
4196
|
record.toString = function() {
|
|
3367
|
-
return JSON.stringify(
|
|
4197
|
+
return JSON.stringify(record);
|
|
3368
4198
|
};
|
|
3369
4199
|
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
|
3370
4200
|
Object.defineProperty(record, prop, { enumerable: false });
|
|
@@ -3382,11 +4212,7 @@ function extractId(value) {
|
|
|
3382
4212
|
function isValidColumn(columns, column) {
|
|
3383
4213
|
if (columns.includes("*"))
|
|
3384
4214
|
return true;
|
|
3385
|
-
|
|
3386
|
-
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
|
3387
|
-
return linkColumns.length > 0;
|
|
3388
|
-
}
|
|
3389
|
-
return columns.includes(column.name);
|
|
4215
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
|
3390
4216
|
}
|
|
3391
4217
|
function parseIfVersion(...args) {
|
|
3392
4218
|
for (const arg of args) {
|
|
@@ -3463,10 +4289,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
|
3463
4289
|
const startsWith = (value) => ({ $startsWith: value });
|
|
3464
4290
|
const endsWith = (value) => ({ $endsWith: value });
|
|
3465
4291
|
const pattern = (value) => ({ $pattern: value });
|
|
4292
|
+
const iPattern = (value) => ({ $iPattern: value });
|
|
3466
4293
|
const is = (value) => ({ $is: value });
|
|
3467
4294
|
const equals = is;
|
|
3468
4295
|
const isNot = (value) => ({ $isNot: value });
|
|
3469
4296
|
const contains = (value) => ({ $contains: value });
|
|
4297
|
+
const iContains = (value) => ({ $iContains: value });
|
|
3470
4298
|
const includes = (value) => ({ $includes: value });
|
|
3471
4299
|
const includesAll = (value) => ({ $includesAll: value });
|
|
3472
4300
|
const includesNone = (value) => ({ $includesNone: value });
|
|
@@ -3583,6 +4411,7 @@ search_fn = async function(query, options, pluginOptions) {
|
|
|
3583
4411
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
|
3584
4412
|
const { records } = await searchBranch({
|
|
3585
4413
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
|
4414
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
|
3586
4415
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
|
3587
4416
|
...pluginOptions
|
|
3588
4417
|
});
|
|
@@ -3600,6 +4429,78 @@ getSchemaTables_fn = async function(pluginOptions) {
|
|
|
3600
4429
|
return schema.tables;
|
|
3601
4430
|
};
|
|
3602
4431
|
|
|
4432
|
+
function escapeElement(elementRepresentation) {
|
|
4433
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
4434
|
+
return '"' + escaped + '"';
|
|
4435
|
+
}
|
|
4436
|
+
function arrayString(val) {
|
|
4437
|
+
let result = "{";
|
|
4438
|
+
for (let i = 0; i < val.length; i++) {
|
|
4439
|
+
if (i > 0) {
|
|
4440
|
+
result = result + ",";
|
|
4441
|
+
}
|
|
4442
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
|
4443
|
+
result = result + "NULL";
|
|
4444
|
+
} else if (Array.isArray(val[i])) {
|
|
4445
|
+
result = result + arrayString(val[i]);
|
|
4446
|
+
} else if (val[i] instanceof Buffer) {
|
|
4447
|
+
result += "\\\\x" + val[i].toString("hex");
|
|
4448
|
+
} else {
|
|
4449
|
+
result += escapeElement(prepareValue(val[i]));
|
|
4450
|
+
}
|
|
4451
|
+
}
|
|
4452
|
+
result = result + "}";
|
|
4453
|
+
return result;
|
|
4454
|
+
}
|
|
4455
|
+
function prepareValue(value) {
|
|
4456
|
+
if (!isDefined(value))
|
|
4457
|
+
return null;
|
|
4458
|
+
if (value instanceof Date) {
|
|
4459
|
+
return value.toISOString();
|
|
4460
|
+
}
|
|
4461
|
+
if (Array.isArray(value)) {
|
|
4462
|
+
return arrayString(value);
|
|
4463
|
+
}
|
|
4464
|
+
if (isObject(value)) {
|
|
4465
|
+
return JSON.stringify(value);
|
|
4466
|
+
}
|
|
4467
|
+
try {
|
|
4468
|
+
return value.toString();
|
|
4469
|
+
} catch (e) {
|
|
4470
|
+
return value;
|
|
4471
|
+
}
|
|
4472
|
+
}
|
|
4473
|
+
function prepareParams(param1, param2) {
|
|
4474
|
+
if (isString(param1)) {
|
|
4475
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
|
4476
|
+
}
|
|
4477
|
+
if (isStringArray(param1)) {
|
|
4478
|
+
const statement = param1.reduce((acc, curr, index) => {
|
|
4479
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
|
4480
|
+
}, "");
|
|
4481
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
|
4482
|
+
}
|
|
4483
|
+
if (isObject(param1)) {
|
|
4484
|
+
const { statement, params, consistency } = param1;
|
|
4485
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
|
4486
|
+
}
|
|
4487
|
+
throw new Error("Invalid query");
|
|
4488
|
+
}
|
|
4489
|
+
|
|
4490
|
+
class SQLPlugin extends XataPlugin {
|
|
4491
|
+
build(pluginOptions) {
|
|
4492
|
+
return async (param1, ...param2) => {
|
|
4493
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
|
4494
|
+
const { records, warning } = await sqlQuery({
|
|
4495
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
|
4496
|
+
body: { statement, params, consistency },
|
|
4497
|
+
...pluginOptions
|
|
4498
|
+
});
|
|
4499
|
+
return { records, warning };
|
|
4500
|
+
};
|
|
4501
|
+
}
|
|
4502
|
+
}
|
|
4503
|
+
|
|
3603
4504
|
class TransactionPlugin extends XataPlugin {
|
|
3604
4505
|
build(pluginOptions) {
|
|
3605
4506
|
return {
|
|
@@ -3654,9 +4555,13 @@ const buildClient = (plugins) => {
|
|
|
3654
4555
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
|
3655
4556
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
|
3656
4557
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
|
4558
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
|
4559
|
+
const files = new FilesPlugin().build(pluginOptions);
|
|
3657
4560
|
this.db = db;
|
|
3658
4561
|
this.search = search;
|
|
3659
4562
|
this.transactions = transactions;
|
|
4563
|
+
this.sql = sql;
|
|
4564
|
+
this.files = files;
|
|
3660
4565
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
|
3661
4566
|
if (namespace === void 0)
|
|
3662
4567
|
continue;
|
|
@@ -3737,6 +4642,7 @@ const buildClient = (plugins) => {
|
|
|
3737
4642
|
fetch,
|
|
3738
4643
|
apiKey,
|
|
3739
4644
|
apiUrl: "",
|
|
4645
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
|
3740
4646
|
workspacesApiUrl: (path, params) => {
|
|
3741
4647
|
const hasBranch = params.dbBranchName ?? params.branch;
|
|
3742
4648
|
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
|
@@ -3843,6 +4749,7 @@ class XataError extends Error {
|
|
|
3843
4749
|
|
|
3844
4750
|
exports.BaseClient = BaseClient;
|
|
3845
4751
|
exports.FetcherError = FetcherError;
|
|
4752
|
+
exports.FilesPlugin = FilesPlugin;
|
|
3846
4753
|
exports.Operations = operationsByTag;
|
|
3847
4754
|
exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
|
|
3848
4755
|
exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
|
|
@@ -3851,8 +4758,10 @@ exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
|
|
|
3851
4758
|
exports.Page = Page;
|
|
3852
4759
|
exports.Query = Query;
|
|
3853
4760
|
exports.RecordArray = RecordArray;
|
|
4761
|
+
exports.RecordColumnTypes = RecordColumnTypes;
|
|
3854
4762
|
exports.Repository = Repository;
|
|
3855
4763
|
exports.RestRepository = RestRepository;
|
|
4764
|
+
exports.SQLPlugin = SQLPlugin;
|
|
3856
4765
|
exports.SchemaPlugin = SchemaPlugin;
|
|
3857
4766
|
exports.SearchPlugin = SearchPlugin;
|
|
3858
4767
|
exports.Serializer = Serializer;
|
|
@@ -3860,6 +4769,7 @@ exports.SimpleCache = SimpleCache;
|
|
|
3860
4769
|
exports.XataApiClient = XataApiClient;
|
|
3861
4770
|
exports.XataApiPlugin = XataApiPlugin;
|
|
3862
4771
|
exports.XataError = XataError;
|
|
4772
|
+
exports.XataFile = XataFile;
|
|
3863
4773
|
exports.XataPlugin = XataPlugin;
|
|
3864
4774
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
|
3865
4775
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
|
@@ -3867,6 +4777,7 @@ exports.addTableColumn = addTableColumn;
|
|
|
3867
4777
|
exports.aggregateTable = aggregateTable;
|
|
3868
4778
|
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
|
3869
4779
|
exports.askTable = askTable;
|
|
4780
|
+
exports.askTableSession = askTableSession;
|
|
3870
4781
|
exports.branchTransaction = branchTransaction;
|
|
3871
4782
|
exports.buildClient = buildClient;
|
|
3872
4783
|
exports.buildPreviewBranchName = buildPreviewBranchName;
|
|
@@ -3880,6 +4791,7 @@ exports.compareMigrationRequest = compareMigrationRequest;
|
|
|
3880
4791
|
exports.contains = contains;
|
|
3881
4792
|
exports.copyBranch = copyBranch;
|
|
3882
4793
|
exports.createBranch = createBranch;
|
|
4794
|
+
exports.createCluster = createCluster;
|
|
3883
4795
|
exports.createDatabase = createDatabase;
|
|
3884
4796
|
exports.createMigrationRequest = createMigrationRequest;
|
|
3885
4797
|
exports.createTable = createTable;
|
|
@@ -3889,18 +4801,24 @@ exports.deleteBranch = deleteBranch;
|
|
|
3889
4801
|
exports.deleteColumn = deleteColumn;
|
|
3890
4802
|
exports.deleteDatabase = deleteDatabase;
|
|
3891
4803
|
exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
|
|
4804
|
+
exports.deleteFile = deleteFile;
|
|
4805
|
+
exports.deleteFileItem = deleteFileItem;
|
|
4806
|
+
exports.deleteOAuthAccessToken = deleteOAuthAccessToken;
|
|
3892
4807
|
exports.deleteRecord = deleteRecord;
|
|
3893
4808
|
exports.deleteTable = deleteTable;
|
|
3894
4809
|
exports.deleteUser = deleteUser;
|
|
3895
4810
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
|
4811
|
+
exports.deleteUserOAuthClient = deleteUserOAuthClient;
|
|
3896
4812
|
exports.deleteWorkspace = deleteWorkspace;
|
|
3897
4813
|
exports.deserialize = deserialize;
|
|
3898
4814
|
exports.endsWith = endsWith;
|
|
3899
4815
|
exports.equals = equals;
|
|
3900
4816
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
|
3901
4817
|
exports.exists = exists;
|
|
4818
|
+
exports.fileAccess = fileAccess;
|
|
3902
4819
|
exports.ge = ge;
|
|
3903
4820
|
exports.getAPIKey = getAPIKey;
|
|
4821
|
+
exports.getAuthorizationCode = getAuthorizationCode;
|
|
3904
4822
|
exports.getBranch = getBranch;
|
|
3905
4823
|
exports.getBranchDetails = getBranchDetails;
|
|
3906
4824
|
exports.getBranchList = getBranchList;
|
|
@@ -3909,11 +4827,14 @@ exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
|
|
3909
4827
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
|
3910
4828
|
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
|
3911
4829
|
exports.getBranchStats = getBranchStats;
|
|
4830
|
+
exports.getCluster = getCluster;
|
|
3912
4831
|
exports.getColumn = getColumn;
|
|
3913
4832
|
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
|
3914
4833
|
exports.getDatabaseList = getDatabaseList;
|
|
3915
4834
|
exports.getDatabaseMetadata = getDatabaseMetadata;
|
|
3916
4835
|
exports.getDatabaseURL = getDatabaseURL;
|
|
4836
|
+
exports.getFile = getFile;
|
|
4837
|
+
exports.getFileItem = getFileItem;
|
|
3917
4838
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
|
3918
4839
|
exports.getHostUrl = getHostUrl;
|
|
3919
4840
|
exports.getMigrationRequest = getMigrationRequest;
|
|
@@ -3924,14 +4845,19 @@ exports.getTableColumns = getTableColumns;
|
|
|
3924
4845
|
exports.getTableSchema = getTableSchema;
|
|
3925
4846
|
exports.getUser = getUser;
|
|
3926
4847
|
exports.getUserAPIKeys = getUserAPIKeys;
|
|
4848
|
+
exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
|
|
4849
|
+
exports.getUserOAuthClients = getUserOAuthClients;
|
|
3927
4850
|
exports.getWorkspace = getWorkspace;
|
|
3928
4851
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
|
3929
4852
|
exports.getWorkspacesList = getWorkspacesList;
|
|
4853
|
+
exports.grantAuthorizationCode = grantAuthorizationCode;
|
|
3930
4854
|
exports.greaterEquals = greaterEquals;
|
|
3931
4855
|
exports.greaterThan = greaterThan;
|
|
3932
4856
|
exports.greaterThanEquals = greaterThanEquals;
|
|
3933
4857
|
exports.gt = gt;
|
|
3934
4858
|
exports.gte = gte;
|
|
4859
|
+
exports.iContains = iContains;
|
|
4860
|
+
exports.iPattern = iPattern;
|
|
3935
4861
|
exports.includes = includes;
|
|
3936
4862
|
exports.includesAll = includesAll;
|
|
3937
4863
|
exports.includesAny = includesAny;
|
|
@@ -3945,11 +4871,14 @@ exports.isHostProviderAlias = isHostProviderAlias;
|
|
|
3945
4871
|
exports.isHostProviderBuilder = isHostProviderBuilder;
|
|
3946
4872
|
exports.isIdentifiable = isIdentifiable;
|
|
3947
4873
|
exports.isNot = isNot;
|
|
4874
|
+
exports.isValidExpandedColumn = isValidExpandedColumn;
|
|
4875
|
+
exports.isValidSelectableColumns = isValidSelectableColumns;
|
|
3948
4876
|
exports.isXataRecord = isXataRecord;
|
|
3949
4877
|
exports.le = le;
|
|
3950
4878
|
exports.lessEquals = lessEquals;
|
|
3951
4879
|
exports.lessThan = lessThan;
|
|
3952
4880
|
exports.lessThanEquals = lessThanEquals;
|
|
4881
|
+
exports.listClusters = listClusters;
|
|
3953
4882
|
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
|
3954
4883
|
exports.listRegions = listRegions;
|
|
3955
4884
|
exports.lt = lt;
|
|
@@ -3962,10 +4891,13 @@ exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
|
|
3962
4891
|
exports.pattern = pattern;
|
|
3963
4892
|
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
|
3964
4893
|
exports.pushBranchMigrations = pushBranchMigrations;
|
|
4894
|
+
exports.putFile = putFile;
|
|
4895
|
+
exports.putFileItem = putFileItem;
|
|
3965
4896
|
exports.queryMigrationRequests = queryMigrationRequests;
|
|
3966
4897
|
exports.queryTable = queryTable;
|
|
3967
4898
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
|
3968
4899
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
|
4900
|
+
exports.renameDatabase = renameDatabase;
|
|
3969
4901
|
exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
|
3970
4902
|
exports.resolveBranch = resolveBranch;
|
|
3971
4903
|
exports.searchBranch = searchBranch;
|
|
@@ -3975,12 +4907,15 @@ exports.setTableSchema = setTableSchema;
|
|
|
3975
4907
|
exports.sqlQuery = sqlQuery;
|
|
3976
4908
|
exports.startsWith = startsWith;
|
|
3977
4909
|
exports.summarizeTable = summarizeTable;
|
|
4910
|
+
exports.transformImage = transformImage;
|
|
3978
4911
|
exports.updateBranchMetadata = updateBranchMetadata;
|
|
3979
4912
|
exports.updateBranchSchema = updateBranchSchema;
|
|
4913
|
+
exports.updateCluster = updateCluster;
|
|
3980
4914
|
exports.updateColumn = updateColumn;
|
|
3981
4915
|
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
|
3982
4916
|
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
|
3983
4917
|
exports.updateMigrationRequest = updateMigrationRequest;
|
|
4918
|
+
exports.updateOAuthAccessToken = updateOAuthAccessToken;
|
|
3984
4919
|
exports.updateRecordWithID = updateRecordWithID;
|
|
3985
4920
|
exports.updateTable = updateTable;
|
|
3986
4921
|
exports.updateUser = updateUser;
|