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