@xata.io/client 0.0.0-alpha.vfc4a5e4 → 0.0.0-alpha.vfc4cc60
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 -9
- package/CHANGELOG.md +125 -1
- package/dist/index.cjs +644 -190
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1141 -362
- package/dist/index.mjs +621 -189
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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) {
|
@@ -30,8 +31,15 @@ function compact(arr) {
|
|
30
31
|
function compactObject(obj) {
|
31
32
|
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
32
33
|
}
|
34
|
+
function isBlob(value) {
|
35
|
+
try {
|
36
|
+
return value instanceof Blob;
|
37
|
+
} catch (error) {
|
38
|
+
return false;
|
39
|
+
}
|
40
|
+
}
|
33
41
|
function isObject(value) {
|
34
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
|
42
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
35
43
|
}
|
36
44
|
function isDefined(value) {
|
37
45
|
return value !== null && value !== void 0;
|
@@ -86,6 +94,27 @@ function chunk(array, chunkSize) {
|
|
86
94
|
async function timeout(ms) {
|
87
95
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
88
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
|
+
}
|
89
118
|
|
90
119
|
function getEnvironment() {
|
91
120
|
try {
|
@@ -185,7 +214,7 @@ function getAPIKey() {
|
|
185
214
|
function getBranch() {
|
186
215
|
try {
|
187
216
|
const { branch } = getEnvironment();
|
188
|
-
return branch
|
217
|
+
return branch;
|
189
218
|
} catch (err) {
|
190
219
|
return void 0;
|
191
220
|
}
|
@@ -213,12 +242,6 @@ function getPreviewBranch() {
|
|
213
242
|
}
|
214
243
|
}
|
215
244
|
|
216
|
-
var __defProp$7 = Object.defineProperty;
|
217
|
-
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
218
|
-
var __publicField$7 = (obj, key, value) => {
|
219
|
-
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
220
|
-
return value;
|
221
|
-
};
|
222
245
|
var __accessCheck$8 = (obj, member, msg) => {
|
223
246
|
if (!member.has(obj))
|
224
247
|
throw TypeError("Cannot " + msg);
|
@@ -242,14 +265,13 @@ var __privateMethod$4 = (obj, member, method) => {
|
|
242
265
|
return method;
|
243
266
|
};
|
244
267
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
245
|
-
const REQUEST_TIMEOUT =
|
268
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
246
269
|
function getFetchImplementation(userFetch) {
|
247
270
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
248
|
-
const
|
271
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
272
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
249
273
|
if (!fetchImpl) {
|
250
|
-
throw new Error(
|
251
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
252
|
-
);
|
274
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
253
275
|
}
|
254
276
|
return fetchImpl;
|
255
277
|
}
|
@@ -259,8 +281,6 @@ class ApiRequestPool {
|
|
259
281
|
__privateAdd$8(this, _fetch, void 0);
|
260
282
|
__privateAdd$8(this, _queue, void 0);
|
261
283
|
__privateAdd$8(this, _concurrency, void 0);
|
262
|
-
__publicField$7(this, "running");
|
263
|
-
__publicField$7(this, "started");
|
264
284
|
__privateSet$8(this, _queue, []);
|
265
285
|
__privateSet$8(this, _concurrency, concurrency);
|
266
286
|
this.running = 0;
|
@@ -277,9 +297,10 @@ class ApiRequestPool {
|
|
277
297
|
}
|
278
298
|
request(url, options) {
|
279
299
|
const start = /* @__PURE__ */ new Date();
|
280
|
-
const
|
300
|
+
const fetchImpl = this.getFetch();
|
281
301
|
const runRequest = async (stalled = false) => {
|
282
|
-
const
|
302
|
+
const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
|
303
|
+
const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
|
283
304
|
if (!response) {
|
284
305
|
throw new Error("Request timed out");
|
285
306
|
}
|
@@ -290,7 +311,7 @@ class ApiRequestPool {
|
|
290
311
|
}
|
291
312
|
if (stalled) {
|
292
313
|
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
293
|
-
console.warn(`A request to Xata hit
|
314
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
294
315
|
}
|
295
316
|
return response;
|
296
317
|
};
|
@@ -505,26 +526,16 @@ function defaultOnOpen(response) {
|
|
505
526
|
}
|
506
527
|
}
|
507
528
|
|
508
|
-
const VERSION = "0.
|
529
|
+
const VERSION = "0.27.0";
|
509
530
|
|
510
|
-
var __defProp$6 = Object.defineProperty;
|
511
|
-
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
512
|
-
var __publicField$6 = (obj, key, value) => {
|
513
|
-
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
514
|
-
return value;
|
515
|
-
};
|
516
531
|
class ErrorWithCause extends Error {
|
517
532
|
constructor(message, options) {
|
518
533
|
super(message, options);
|
519
|
-
__publicField$6(this, "cause");
|
520
534
|
}
|
521
535
|
}
|
522
536
|
class FetcherError extends ErrorWithCause {
|
523
537
|
constructor(status, data, requestId) {
|
524
538
|
super(getMessage(data));
|
525
|
-
__publicField$6(this, "status");
|
526
|
-
__publicField$6(this, "requestId");
|
527
|
-
__publicField$6(this, "errors");
|
528
539
|
this.status = status;
|
529
540
|
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
530
541
|
this.requestId = requestId;
|
@@ -591,11 +602,14 @@ function hostHeader(url) {
|
|
591
602
|
const { groups } = pattern.exec(url) ?? {};
|
592
603
|
return groups?.host ? { Host: groups.host } : {};
|
593
604
|
}
|
594
|
-
function parseBody(body, headers) {
|
605
|
+
async function parseBody(body, headers) {
|
595
606
|
if (!isDefined(body))
|
596
607
|
return void 0;
|
608
|
+
if (isBlob(body) || typeof body.text === "function") {
|
609
|
+
return body;
|
610
|
+
}
|
597
611
|
const { "Content-Type": contentType } = headers ?? {};
|
598
|
-
if (String(contentType).toLowerCase() === "application/json") {
|
612
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
599
613
|
return JSON.stringify(body);
|
600
614
|
}
|
601
615
|
return body;
|
@@ -652,7 +666,7 @@ async function fetch$1({
|
|
652
666
|
const response = await pool.request(url, {
|
653
667
|
...fetchOptions,
|
654
668
|
method: method.toUpperCase(),
|
655
|
-
body: parseBody(body, headers),
|
669
|
+
body: await parseBody(body, headers),
|
656
670
|
headers,
|
657
671
|
signal
|
658
672
|
});
|
@@ -663,7 +677,8 @@ async function fetch$1({
|
|
663
677
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
664
678
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
665
679
|
[TraceAttributes.HTTP_HOST]: host,
|
666
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
680
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
681
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
667
682
|
});
|
668
683
|
const message = response.headers?.get("x-xata-message");
|
669
684
|
if (message)
|
@@ -751,6 +766,18 @@ function parseUrl(url) {
|
|
751
766
|
|
752
767
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
753
768
|
|
769
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({
|
770
|
+
url: "/db/{dbBranchName}/pgroll/apply",
|
771
|
+
method: "post",
|
772
|
+
...variables,
|
773
|
+
signal
|
774
|
+
});
|
775
|
+
const pgRollStatus = (variables, signal) => dataPlaneFetch({
|
776
|
+
url: "/db/{dbBranchName}/pgroll/status",
|
777
|
+
method: "get",
|
778
|
+
...variables,
|
779
|
+
signal
|
780
|
+
});
|
754
781
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
755
782
|
url: "/dbs/{dbName}",
|
756
783
|
method: "get",
|
@@ -770,6 +797,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
770
797
|
...variables,
|
771
798
|
signal
|
772
799
|
});
|
800
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
801
|
+
url: "/db/{dbBranchName}/schema",
|
802
|
+
method: "get",
|
803
|
+
...variables,
|
804
|
+
signal
|
805
|
+
});
|
773
806
|
const copyBranch = (variables, signal) => dataPlaneFetch({
|
774
807
|
url: "/db/{dbBranchName}/copy",
|
775
808
|
method: "post",
|
@@ -935,12 +968,6 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
935
968
|
...variables,
|
936
969
|
signal
|
937
970
|
});
|
938
|
-
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
939
|
-
url: "/db/{dbBranchName}/sql",
|
940
|
-
method: "post",
|
941
|
-
...variables,
|
942
|
-
signal
|
943
|
-
});
|
944
971
|
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
945
972
|
const askTable = (variables, signal) => dataPlaneFetch({
|
946
973
|
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
@@ -948,7 +975,7 @@ const askTable = (variables, signal) => dataPlaneFetch({
|
|
948
975
|
...variables,
|
949
976
|
signal
|
950
977
|
});
|
951
|
-
const
|
978
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
952
979
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
953
980
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
954
981
|
const fileAccess = (variables, signal) => dataPlaneFetch({
|
@@ -957,8 +984,16 @@ const fileAccess = (variables, signal) => dataPlaneFetch({
|
|
957
984
|
...variables,
|
958
985
|
signal
|
959
986
|
});
|
987
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
988
|
+
url: "/db/{dbBranchName}/sql",
|
989
|
+
method: "post",
|
990
|
+
...variables,
|
991
|
+
signal
|
992
|
+
});
|
960
993
|
const operationsByTag$2 = {
|
961
994
|
branch: {
|
995
|
+
applyMigration,
|
996
|
+
pgRollStatus,
|
962
997
|
getBranchList,
|
963
998
|
getBranchDetails,
|
964
999
|
createBranch,
|
@@ -973,6 +1008,7 @@ const operationsByTag$2 = {
|
|
973
1008
|
resolveBranch
|
974
1009
|
},
|
975
1010
|
migrations: {
|
1011
|
+
getSchema,
|
976
1012
|
getBranchMigrationHistory,
|
977
1013
|
getBranchMigrationPlan,
|
978
1014
|
executeBranchMigrationPlan,
|
@@ -1021,17 +1057,19 @@ const operationsByTag$2 = {
|
|
1021
1057
|
queryTable,
|
1022
1058
|
searchBranch,
|
1023
1059
|
searchTable,
|
1024
|
-
sqlQuery,
|
1025
1060
|
vectorSearchTable,
|
1026
1061
|
askTable,
|
1027
|
-
|
1062
|
+
askTableSession,
|
1028
1063
|
summarizeTable,
|
1029
1064
|
aggregateTable
|
1030
|
-
}
|
1065
|
+
},
|
1066
|
+
sql: { sqlQuery }
|
1031
1067
|
};
|
1032
1068
|
|
1033
1069
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
1034
1070
|
|
1071
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
1072
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
1035
1073
|
const getUser = (variables, signal) => controlPlaneFetch({
|
1036
1074
|
url: "/user",
|
1037
1075
|
method: "get",
|
@@ -1068,6 +1106,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
1068
1106
|
...variables,
|
1069
1107
|
signal
|
1070
1108
|
});
|
1109
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
1110
|
+
url: "/user/oauth/clients",
|
1111
|
+
method: "get",
|
1112
|
+
...variables,
|
1113
|
+
signal
|
1114
|
+
});
|
1115
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1116
|
+
url: "/user/oauth/clients/{clientId}",
|
1117
|
+
method: "delete",
|
1118
|
+
...variables,
|
1119
|
+
signal
|
1120
|
+
});
|
1121
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1122
|
+
url: "/user/oauth/tokens",
|
1123
|
+
method: "get",
|
1124
|
+
...variables,
|
1125
|
+
signal
|
1126
|
+
});
|
1127
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
1128
|
+
url: "/user/oauth/tokens/{token}",
|
1129
|
+
method: "delete",
|
1130
|
+
...variables,
|
1131
|
+
signal
|
1132
|
+
});
|
1133
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
1071
1134
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
1072
1135
|
url: "/workspaces",
|
1073
1136
|
method: "get",
|
@@ -1111,6 +1174,20 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
|
|
1111
1174
|
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
1112
1175
|
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
1113
1176
|
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1177
|
+
const listClusters = (variables, signal) => controlPlaneFetch({
|
1178
|
+
url: "/workspaces/{workspaceId}/clusters",
|
1179
|
+
method: "get",
|
1180
|
+
...variables,
|
1181
|
+
signal
|
1182
|
+
});
|
1183
|
+
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
1184
|
+
const getCluster = (variables, signal) => controlPlaneFetch({
|
1185
|
+
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
1186
|
+
method: "get",
|
1187
|
+
...variables,
|
1188
|
+
signal
|
1189
|
+
});
|
1190
|
+
const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
|
1114
1191
|
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
1115
1192
|
url: "/workspaces/{workspaceId}/dbs",
|
1116
1193
|
method: "get",
|
@@ -1137,6 +1214,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
1137
1214
|
signal
|
1138
1215
|
});
|
1139
1216
|
const operationsByTag$1 = {
|
1217
|
+
oAuth: {
|
1218
|
+
getAuthorizationCode,
|
1219
|
+
grantAuthorizationCode,
|
1220
|
+
getUserOAuthClients,
|
1221
|
+
deleteUserOAuthClient,
|
1222
|
+
getUserOAuthAccessTokens,
|
1223
|
+
deleteOAuthAccessToken,
|
1224
|
+
updateOAuthAccessToken
|
1225
|
+
},
|
1140
1226
|
users: { getUser, updateUser, deleteUser },
|
1141
1227
|
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
1142
1228
|
workspaces: {
|
@@ -1156,6 +1242,7 @@ const operationsByTag$1 = {
|
|
1156
1242
|
acceptWorkspaceMemberInvite,
|
1157
1243
|
resendWorkspaceMemberInvite
|
1158
1244
|
},
|
1245
|
+
xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
|
1159
1246
|
databases: {
|
1160
1247
|
getDatabaseList,
|
1161
1248
|
createDatabase,
|
@@ -2149,7 +2236,7 @@ class SearchAndFilterApi {
|
|
2149
2236
|
...this.extraProps
|
2150
2237
|
});
|
2151
2238
|
}
|
2152
|
-
|
2239
|
+
askTableSession({
|
2153
2240
|
workspace,
|
2154
2241
|
region,
|
2155
2242
|
database,
|
@@ -2158,7 +2245,7 @@ class SearchAndFilterApi {
|
|
2158
2245
|
sessionId,
|
2159
2246
|
message
|
2160
2247
|
}) {
|
2161
|
-
return operationsByTag.searchAndFilter.
|
2248
|
+
return operationsByTag.searchAndFilter.askTableSession({
|
2162
2249
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
2163
2250
|
body: { message },
|
2164
2251
|
...this.extraProps
|
@@ -2455,11 +2542,13 @@ class DatabaseApi {
|
|
2455
2542
|
createDatabase({
|
2456
2543
|
workspace,
|
2457
2544
|
database,
|
2458
|
-
data
|
2545
|
+
data,
|
2546
|
+
headers
|
2459
2547
|
}) {
|
2460
2548
|
return operationsByTag.databases.createDatabase({
|
2461
2549
|
pathParams: { workspaceId: workspace, dbName: database },
|
2462
2550
|
body: data,
|
2551
|
+
headers,
|
2463
2552
|
...this.extraProps
|
2464
2553
|
});
|
2465
2554
|
}
|
@@ -2549,6 +2638,148 @@ class XataApiPlugin {
|
|
2549
2638
|
class XataPlugin {
|
2550
2639
|
}
|
2551
2640
|
|
2641
|
+
function buildTransformString(transformations) {
|
2642
|
+
return transformations.flatMap(
|
2643
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
2644
|
+
if (key === "trim") {
|
2645
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
2646
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
2647
|
+
}
|
2648
|
+
if (key === "gravity" && typeof value === "object") {
|
2649
|
+
const { x = 0.5, y = 0.5 } = value;
|
2650
|
+
return `${key}=${[x, y].join("x")}`;
|
2651
|
+
}
|
2652
|
+
return `${key}=${value}`;
|
2653
|
+
})
|
2654
|
+
).join(",");
|
2655
|
+
}
|
2656
|
+
function transformImage(url, ...transformations) {
|
2657
|
+
if (!isDefined(url))
|
2658
|
+
return void 0;
|
2659
|
+
const newTransformations = buildTransformString(transformations);
|
2660
|
+
const { hostname, pathname, search } = new URL(url);
|
2661
|
+
const pathParts = pathname.split("/");
|
2662
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
2663
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
2664
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
2665
|
+
const path = pathParts.join("/");
|
2666
|
+
return `https://${hostname}${transform}${path}${search}`;
|
2667
|
+
}
|
2668
|
+
|
2669
|
+
class XataFile {
|
2670
|
+
constructor(file) {
|
2671
|
+
this.id = file.id;
|
2672
|
+
this.name = file.name || "";
|
2673
|
+
this.mediaType = file.mediaType || "application/octet-stream";
|
2674
|
+
this.base64Content = file.base64Content;
|
2675
|
+
this.enablePublicUrl = file.enablePublicUrl ?? false;
|
2676
|
+
this.signedUrlTimeout = file.signedUrlTimeout ?? 300;
|
2677
|
+
this.size = file.size ?? 0;
|
2678
|
+
this.version = file.version ?? 1;
|
2679
|
+
this.url = file.url || "";
|
2680
|
+
this.signedUrl = file.signedUrl;
|
2681
|
+
this.attributes = file.attributes || {};
|
2682
|
+
}
|
2683
|
+
static fromBuffer(buffer, options = {}) {
|
2684
|
+
const base64Content = buffer.toString("base64");
|
2685
|
+
return new XataFile({ ...options, base64Content });
|
2686
|
+
}
|
2687
|
+
toBuffer() {
|
2688
|
+
if (!this.base64Content) {
|
2689
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2690
|
+
}
|
2691
|
+
return Buffer.from(this.base64Content, "base64");
|
2692
|
+
}
|
2693
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
2694
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
2695
|
+
return this.fromUint8Array(uint8Array, options);
|
2696
|
+
}
|
2697
|
+
toArrayBuffer() {
|
2698
|
+
if (!this.base64Content) {
|
2699
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2700
|
+
}
|
2701
|
+
const binary = atob(this.base64Content);
|
2702
|
+
return new ArrayBuffer(binary.length);
|
2703
|
+
}
|
2704
|
+
static fromUint8Array(uint8Array, options = {}) {
|
2705
|
+
let binary = "";
|
2706
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
2707
|
+
binary += String.fromCharCode(uint8Array[i]);
|
2708
|
+
}
|
2709
|
+
const base64Content = btoa(binary);
|
2710
|
+
return new XataFile({ ...options, base64Content });
|
2711
|
+
}
|
2712
|
+
toUint8Array() {
|
2713
|
+
if (!this.base64Content) {
|
2714
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2715
|
+
}
|
2716
|
+
const binary = atob(this.base64Content);
|
2717
|
+
const uint8Array = new Uint8Array(binary.length);
|
2718
|
+
for (let i = 0; i < binary.length; i++) {
|
2719
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2720
|
+
}
|
2721
|
+
return uint8Array;
|
2722
|
+
}
|
2723
|
+
static async fromBlob(file, options = {}) {
|
2724
|
+
const name = options.name ?? file.name;
|
2725
|
+
const mediaType = file.type;
|
2726
|
+
const arrayBuffer = await file.arrayBuffer();
|
2727
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
2728
|
+
}
|
2729
|
+
toBlob() {
|
2730
|
+
if (!this.base64Content) {
|
2731
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2732
|
+
}
|
2733
|
+
const binary = atob(this.base64Content);
|
2734
|
+
const uint8Array = new Uint8Array(binary.length);
|
2735
|
+
for (let i = 0; i < binary.length; i++) {
|
2736
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2737
|
+
}
|
2738
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
2739
|
+
}
|
2740
|
+
static fromString(string, options = {}) {
|
2741
|
+
const base64Content = btoa(string);
|
2742
|
+
return new XataFile({ ...options, base64Content });
|
2743
|
+
}
|
2744
|
+
toString() {
|
2745
|
+
if (!this.base64Content) {
|
2746
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2747
|
+
}
|
2748
|
+
return atob(this.base64Content);
|
2749
|
+
}
|
2750
|
+
static fromBase64(base64Content, options = {}) {
|
2751
|
+
return new XataFile({ ...options, base64Content });
|
2752
|
+
}
|
2753
|
+
toBase64() {
|
2754
|
+
if (!this.base64Content) {
|
2755
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2756
|
+
}
|
2757
|
+
return this.base64Content;
|
2758
|
+
}
|
2759
|
+
transform(...options) {
|
2760
|
+
return {
|
2761
|
+
url: transformImage(this.url, ...options),
|
2762
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
2763
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
2764
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
2765
|
+
};
|
2766
|
+
}
|
2767
|
+
}
|
2768
|
+
const parseInputFileEntry = async (entry) => {
|
2769
|
+
if (!isDefined(entry))
|
2770
|
+
return null;
|
2771
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2772
|
+
return compactObject({
|
2773
|
+
id,
|
2774
|
+
// Name cannot be an empty string in our API
|
2775
|
+
name: name ? name : void 0,
|
2776
|
+
mediaType,
|
2777
|
+
base64Content,
|
2778
|
+
enablePublicUrl,
|
2779
|
+
signedUrlTimeout
|
2780
|
+
});
|
2781
|
+
};
|
2782
|
+
|
2552
2783
|
function cleanFilter(filter) {
|
2553
2784
|
if (!isDefined(filter))
|
2554
2785
|
return void 0;
|
@@ -2576,12 +2807,25 @@ function cleanFilter(filter) {
|
|
2576
2807
|
return Object.keys(values).length > 0 ? values : void 0;
|
2577
2808
|
}
|
2578
2809
|
|
2579
|
-
|
2580
|
-
|
2581
|
-
|
2582
|
-
|
2583
|
-
|
2584
|
-
|
2810
|
+
function stringifyJson(value) {
|
2811
|
+
if (!isDefined(value))
|
2812
|
+
return value;
|
2813
|
+
if (isString(value))
|
2814
|
+
return value;
|
2815
|
+
try {
|
2816
|
+
return JSON.stringify(value);
|
2817
|
+
} catch (e) {
|
2818
|
+
return value;
|
2819
|
+
}
|
2820
|
+
}
|
2821
|
+
function parseJson(value) {
|
2822
|
+
try {
|
2823
|
+
return JSON.parse(value);
|
2824
|
+
} catch (e) {
|
2825
|
+
return value;
|
2826
|
+
}
|
2827
|
+
}
|
2828
|
+
|
2585
2829
|
var __accessCheck$6 = (obj, member, msg) => {
|
2586
2830
|
if (!member.has(obj))
|
2587
2831
|
throw TypeError("Cannot " + msg);
|
@@ -2604,14 +2848,6 @@ var _query, _page;
|
|
2604
2848
|
class Page {
|
2605
2849
|
constructor(query, meta, records = []) {
|
2606
2850
|
__privateAdd$6(this, _query, void 0);
|
2607
|
-
/**
|
2608
|
-
* Page metadata, required to retrieve additional records.
|
2609
|
-
*/
|
2610
|
-
__publicField$5(this, "meta");
|
2611
|
-
/**
|
2612
|
-
* The set of results for this page.
|
2613
|
-
*/
|
2614
|
-
__publicField$5(this, "records");
|
2615
2851
|
__privateSet$6(this, _query, query);
|
2616
2852
|
this.meta = meta;
|
2617
2853
|
this.records = new RecordArray(this, records);
|
@@ -2661,9 +2897,9 @@ class Page {
|
|
2661
2897
|
}
|
2662
2898
|
}
|
2663
2899
|
_query = new WeakMap();
|
2664
|
-
const PAGINATION_MAX_SIZE =
|
2900
|
+
const PAGINATION_MAX_SIZE = 1e3;
|
2665
2901
|
const PAGINATION_DEFAULT_SIZE = 20;
|
2666
|
-
const PAGINATION_MAX_OFFSET =
|
2902
|
+
const PAGINATION_MAX_OFFSET = 49e3;
|
2667
2903
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
2668
2904
|
function isCursorPaginationOptions(options) {
|
2669
2905
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
@@ -2742,12 +2978,6 @@ const _RecordArray = class _RecordArray extends Array {
|
|
2742
2978
|
_page = new WeakMap();
|
2743
2979
|
let RecordArray = _RecordArray;
|
2744
2980
|
|
2745
|
-
var __defProp$4 = Object.defineProperty;
|
2746
|
-
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2747
|
-
var __publicField$4 = (obj, key, value) => {
|
2748
|
-
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2749
|
-
return value;
|
2750
|
-
};
|
2751
2981
|
var __accessCheck$5 = (obj, member, msg) => {
|
2752
2982
|
if (!member.has(obj))
|
2753
2983
|
throw TypeError("Cannot " + msg);
|
@@ -2778,8 +3008,8 @@ const _Query = class _Query {
|
|
2778
3008
|
__privateAdd$5(this, _repository, void 0);
|
2779
3009
|
__privateAdd$5(this, _data, { filter: {} });
|
2780
3010
|
// Implements pagination
|
2781
|
-
|
2782
|
-
|
3011
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
3012
|
+
this.records = new RecordArray(this, []);
|
2783
3013
|
__privateSet$5(this, _table$1, table);
|
2784
3014
|
if (repository) {
|
2785
3015
|
__privateSet$5(this, _repository, repository);
|
@@ -3034,7 +3264,8 @@ const RecordColumnTypes = [
|
|
3034
3264
|
"datetime",
|
3035
3265
|
"vector",
|
3036
3266
|
"file[]",
|
3037
|
-
"file"
|
3267
|
+
"file",
|
3268
|
+
"json"
|
3038
3269
|
];
|
3039
3270
|
function isIdentifiable(x) {
|
3040
3271
|
return isObject(x) && isString(x?.id);
|
@@ -3045,6 +3276,24 @@ function isXataRecord(x) {
|
|
3045
3276
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
3046
3277
|
}
|
3047
3278
|
|
3279
|
+
function isValidExpandedColumn(column) {
|
3280
|
+
return isObject(column) && isString(column.name);
|
3281
|
+
}
|
3282
|
+
function isValidSelectableColumns(columns) {
|
3283
|
+
if (!Array.isArray(columns)) {
|
3284
|
+
return false;
|
3285
|
+
}
|
3286
|
+
return columns.every((column) => {
|
3287
|
+
if (typeof column === "string") {
|
3288
|
+
return true;
|
3289
|
+
}
|
3290
|
+
if (typeof column === "object") {
|
3291
|
+
return isValidExpandedColumn(column);
|
3292
|
+
}
|
3293
|
+
return false;
|
3294
|
+
});
|
3295
|
+
}
|
3296
|
+
|
3048
3297
|
function isSortFilterString(value) {
|
3049
3298
|
return isString(value);
|
3050
3299
|
}
|
@@ -3094,7 +3343,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
3094
3343
|
__accessCheck$4(obj, member, "access private method");
|
3095
3344
|
return method;
|
3096
3345
|
};
|
3097
|
-
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;
|
3346
|
+
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;
|
3098
3347
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
3099
3348
|
class Repository extends Query {
|
3100
3349
|
}
|
@@ -3116,6 +3365,7 @@ class RestRepository extends Query {
|
|
3116
3365
|
__privateAdd$4(this, _setCacheQuery);
|
3117
3366
|
__privateAdd$4(this, _getCacheQuery);
|
3118
3367
|
__privateAdd$4(this, _getSchemaTables$1);
|
3368
|
+
__privateAdd$4(this, _transformObjectToApi);
|
3119
3369
|
__privateAdd$4(this, _table, void 0);
|
3120
3370
|
__privateAdd$4(this, _getFetchProps, void 0);
|
3121
3371
|
__privateAdd$4(this, _db, void 0);
|
@@ -3144,24 +3394,24 @@ class RestRepository extends Query {
|
|
3144
3394
|
if (a.length === 0)
|
3145
3395
|
return [];
|
3146
3396
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
3147
|
-
const columns =
|
3397
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3148
3398
|
const result = await this.read(ids, columns);
|
3149
3399
|
return result;
|
3150
3400
|
}
|
3151
3401
|
if (isString(a) && isObject(b)) {
|
3152
3402
|
if (a === "")
|
3153
3403
|
throw new Error("The id can't be empty");
|
3154
|
-
const columns =
|
3404
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3155
3405
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
3156
3406
|
}
|
3157
3407
|
if (isObject(a) && isString(a.id)) {
|
3158
3408
|
if (a.id === "")
|
3159
3409
|
throw new Error("The id can't be empty");
|
3160
|
-
const columns =
|
3410
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3161
3411
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
3162
3412
|
}
|
3163
3413
|
if (isObject(a)) {
|
3164
|
-
const columns =
|
3414
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3165
3415
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
3166
3416
|
}
|
3167
3417
|
throw new Error("Invalid arguments for create method");
|
@@ -3169,7 +3419,7 @@ class RestRepository extends Query {
|
|
3169
3419
|
}
|
3170
3420
|
async read(a, b) {
|
3171
3421
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
3172
|
-
const columns =
|
3422
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3173
3423
|
if (Array.isArray(a)) {
|
3174
3424
|
if (a.length === 0)
|
3175
3425
|
return [];
|
@@ -3196,7 +3446,13 @@ class RestRepository extends Query {
|
|
3196
3446
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3197
3447
|
});
|
3198
3448
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3199
|
-
return initObject(
|
3449
|
+
return initObject(
|
3450
|
+
__privateGet$4(this, _db),
|
3451
|
+
schemaTables,
|
3452
|
+
__privateGet$4(this, _table),
|
3453
|
+
response,
|
3454
|
+
columns
|
3455
|
+
);
|
3200
3456
|
} catch (e) {
|
3201
3457
|
if (isObject(e) && e.status === 404) {
|
3202
3458
|
return null;
|
@@ -3238,17 +3494,17 @@ class RestRepository extends Query {
|
|
3238
3494
|
ifVersion,
|
3239
3495
|
upsert: false
|
3240
3496
|
});
|
3241
|
-
const columns =
|
3497
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3242
3498
|
const result = await this.read(a, columns);
|
3243
3499
|
return result;
|
3244
3500
|
}
|
3245
3501
|
try {
|
3246
3502
|
if (isString(a) && isObject(b)) {
|
3247
|
-
const columns =
|
3503
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3248
3504
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3249
3505
|
}
|
3250
3506
|
if (isObject(a) && isString(a.id)) {
|
3251
|
-
const columns =
|
3507
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3252
3508
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3253
3509
|
}
|
3254
3510
|
} catch (error) {
|
@@ -3288,20 +3544,20 @@ class RestRepository extends Query {
|
|
3288
3544
|
ifVersion,
|
3289
3545
|
upsert: true
|
3290
3546
|
});
|
3291
|
-
const columns =
|
3547
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3292
3548
|
const result = await this.read(a, columns);
|
3293
3549
|
return result;
|
3294
3550
|
}
|
3295
3551
|
if (isString(a) && isObject(b)) {
|
3296
3552
|
if (a === "")
|
3297
3553
|
throw new Error("The id can't be empty");
|
3298
|
-
const columns =
|
3554
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3299
3555
|
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3300
3556
|
}
|
3301
3557
|
if (isObject(a) && isString(a.id)) {
|
3302
3558
|
if (a.id === "")
|
3303
3559
|
throw new Error("The id can't be empty");
|
3304
|
-
const columns =
|
3560
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3305
3561
|
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3306
3562
|
}
|
3307
3563
|
if (!isDefined(a) && isObject(b)) {
|
@@ -3320,20 +3576,20 @@ class RestRepository extends Query {
|
|
3320
3576
|
if (a.length === 0)
|
3321
3577
|
return [];
|
3322
3578
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
3323
|
-
const columns =
|
3579
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3324
3580
|
const result = await this.read(ids, columns);
|
3325
3581
|
return result;
|
3326
3582
|
}
|
3327
3583
|
if (isString(a) && isObject(b)) {
|
3328
3584
|
if (a === "")
|
3329
3585
|
throw new Error("The id can't be empty");
|
3330
|
-
const columns =
|
3586
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3331
3587
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3332
3588
|
}
|
3333
3589
|
if (isObject(a) && isString(a.id)) {
|
3334
3590
|
if (a.id === "")
|
3335
3591
|
throw new Error("The id can't be empty");
|
3336
|
-
const columns =
|
3592
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3337
3593
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3338
3594
|
}
|
3339
3595
|
if (!isDefined(a) && isObject(b)) {
|
@@ -3357,7 +3613,7 @@ class RestRepository extends Query {
|
|
3357
3613
|
return o.id;
|
3358
3614
|
throw new Error("Invalid arguments for delete method");
|
3359
3615
|
});
|
3360
|
-
const columns =
|
3616
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3361
3617
|
const result = await this.read(a, columns);
|
3362
3618
|
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
3363
3619
|
return result;
|
@@ -3391,7 +3647,7 @@ class RestRepository extends Query {
|
|
3391
3647
|
}
|
3392
3648
|
async search(query, options = {}) {
|
3393
3649
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
3394
|
-
const { records } = await searchTable({
|
3650
|
+
const { records, totalCount } = await searchTable({
|
3395
3651
|
pathParams: {
|
3396
3652
|
workspace: "{workspaceId}",
|
3397
3653
|
dbBranchName: "{dbBranch}",
|
@@ -3411,12 +3667,15 @@ class RestRepository extends Query {
|
|
3411
3667
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3412
3668
|
});
|
3413
3669
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3414
|
-
return
|
3670
|
+
return {
|
3671
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3672
|
+
totalCount
|
3673
|
+
};
|
3415
3674
|
});
|
3416
3675
|
}
|
3417
3676
|
async vectorSearch(column, query, options) {
|
3418
3677
|
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3419
|
-
const { records } = await vectorSearchTable({
|
3678
|
+
const { records, totalCount } = await vectorSearchTable({
|
3420
3679
|
pathParams: {
|
3421
3680
|
workspace: "{workspaceId}",
|
3422
3681
|
dbBranchName: "{dbBranch}",
|
@@ -3433,7 +3692,10 @@ class RestRepository extends Query {
|
|
3433
3692
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3434
3693
|
});
|
3435
3694
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3436
|
-
return
|
3695
|
+
return {
|
3696
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3697
|
+
totalCount
|
3698
|
+
};
|
3437
3699
|
});
|
3438
3700
|
}
|
3439
3701
|
async aggregate(aggs, filter) {
|
@@ -3476,7 +3738,13 @@ class RestRepository extends Query {
|
|
3476
3738
|
});
|
3477
3739
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3478
3740
|
const records = objects.map(
|
3479
|
-
(record) => initObject(
|
3741
|
+
(record) => initObject(
|
3742
|
+
__privateGet$4(this, _db),
|
3743
|
+
schemaTables,
|
3744
|
+
__privateGet$4(this, _table),
|
3745
|
+
record,
|
3746
|
+
data.columns ?? ["*"]
|
3747
|
+
)
|
3480
3748
|
);
|
3481
3749
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
3482
3750
|
return new Page(query, meta, records);
|
@@ -3503,27 +3771,38 @@ class RestRepository extends Query {
|
|
3503
3771
|
},
|
3504
3772
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3505
3773
|
});
|
3506
|
-
|
3774
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3775
|
+
return {
|
3776
|
+
...result,
|
3777
|
+
summaries: result.summaries.map(
|
3778
|
+
(summary) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), summary, data.columns ?? [])
|
3779
|
+
)
|
3780
|
+
};
|
3507
3781
|
});
|
3508
3782
|
}
|
3509
3783
|
ask(question, options) {
|
3784
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
3510
3785
|
const params = {
|
3511
3786
|
pathParams: {
|
3512
3787
|
workspace: "{workspaceId}",
|
3513
3788
|
dbBranchName: "{dbBranch}",
|
3514
3789
|
region: "{region}",
|
3515
|
-
tableName: __privateGet$4(this, _table)
|
3790
|
+
tableName: __privateGet$4(this, _table),
|
3791
|
+
sessionId: options?.sessionId
|
3516
3792
|
},
|
3517
3793
|
body: {
|
3518
|
-
|
3519
|
-
|
3794
|
+
...questionParam,
|
3795
|
+
rules: options?.rules,
|
3796
|
+
searchType: options?.searchType,
|
3797
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
3798
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
3520
3799
|
},
|
3521
3800
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3522
3801
|
};
|
3523
3802
|
if (options?.onMessage) {
|
3524
3803
|
fetchSSERequest({
|
3525
3804
|
endpoint: "dataPlane",
|
3526
|
-
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
3805
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
3527
3806
|
method: "POST",
|
3528
3807
|
onMessage: (message) => {
|
3529
3808
|
options.onMessage?.({ answer: message.text, records: message.records });
|
@@ -3531,7 +3810,7 @@ class RestRepository extends Query {
|
|
3531
3810
|
...params
|
3532
3811
|
});
|
3533
3812
|
} else {
|
3534
|
-
return
|
3813
|
+
return askTableSession(params);
|
3535
3814
|
}
|
3536
3815
|
}
|
3537
3816
|
}
|
@@ -3543,7 +3822,7 @@ _schemaTables$2 = new WeakMap();
|
|
3543
3822
|
_trace = new WeakMap();
|
3544
3823
|
_insertRecordWithoutId = new WeakSet();
|
3545
3824
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
3546
|
-
const record =
|
3825
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3547
3826
|
const response = await insertRecord({
|
3548
3827
|
pathParams: {
|
3549
3828
|
workspace: "{workspaceId}",
|
@@ -3562,7 +3841,7 @@ _insertRecordWithId = new WeakSet();
|
|
3562
3841
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
3563
3842
|
if (!recordId)
|
3564
3843
|
return null;
|
3565
|
-
const record =
|
3844
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3566
3845
|
const response = await insertRecordWithID({
|
3567
3846
|
pathParams: {
|
3568
3847
|
workspace: "{workspaceId}",
|
@@ -3580,21 +3859,20 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
3580
3859
|
};
|
3581
3860
|
_insertRecords = new WeakSet();
|
3582
3861
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
3583
|
-
const
|
3584
|
-
|
3585
|
-
|
3586
|
-
|
3587
|
-
|
3588
|
-
);
|
3862
|
+
const operations = await promiseMap(objects, async (object) => {
|
3863
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3864
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
3865
|
+
});
|
3866
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
3589
3867
|
const ids = [];
|
3590
|
-
for (const
|
3868
|
+
for (const operations2 of chunkedOperations) {
|
3591
3869
|
const { results } = await branchTransaction({
|
3592
3870
|
pathParams: {
|
3593
3871
|
workspace: "{workspaceId}",
|
3594
3872
|
dbBranchName: "{dbBranch}",
|
3595
3873
|
region: "{region}"
|
3596
3874
|
},
|
3597
|
-
body: { operations },
|
3875
|
+
body: { operations: operations2 },
|
3598
3876
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3599
3877
|
});
|
3600
3878
|
for (const result of results) {
|
@@ -3611,7 +3889,7 @@ _updateRecordWithID = new WeakSet();
|
|
3611
3889
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
3612
3890
|
if (!recordId)
|
3613
3891
|
return null;
|
3614
|
-
const { id: _id, ...record } =
|
3892
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3615
3893
|
try {
|
3616
3894
|
const response = await updateRecordWithID({
|
3617
3895
|
pathParams: {
|
@@ -3636,21 +3914,20 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
3636
3914
|
};
|
3637
3915
|
_updateRecords = new WeakSet();
|
3638
3916
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
3639
|
-
const
|
3640
|
-
|
3641
|
-
|
3642
|
-
|
3643
|
-
|
3644
|
-
);
|
3917
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
3918
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3919
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
3920
|
+
});
|
3921
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
3645
3922
|
const ids = [];
|
3646
|
-
for (const
|
3923
|
+
for (const operations2 of chunkedOperations) {
|
3647
3924
|
const { results } = await branchTransaction({
|
3648
3925
|
pathParams: {
|
3649
3926
|
workspace: "{workspaceId}",
|
3650
3927
|
dbBranchName: "{dbBranch}",
|
3651
3928
|
region: "{region}"
|
3652
3929
|
},
|
3653
|
-
body: { operations },
|
3930
|
+
body: { operations: operations2 },
|
3654
3931
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3655
3932
|
});
|
3656
3933
|
for (const result of results) {
|
@@ -3753,12 +4030,40 @@ getSchemaTables_fn$1 = async function() {
|
|
3753
4030
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
3754
4031
|
return schema.tables;
|
3755
4032
|
};
|
3756
|
-
|
3757
|
-
|
4033
|
+
_transformObjectToApi = new WeakSet();
|
4034
|
+
transformObjectToApi_fn = async function(object) {
|
4035
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
4036
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
4037
|
+
if (!schema)
|
4038
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
4039
|
+
const result = {};
|
4040
|
+
for (const [key, value] of Object.entries(object)) {
|
3758
4041
|
if (key === "xata")
|
3759
|
-
|
3760
|
-
|
3761
|
-
|
4042
|
+
continue;
|
4043
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
4044
|
+
switch (type) {
|
4045
|
+
case "link": {
|
4046
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
4047
|
+
break;
|
4048
|
+
}
|
4049
|
+
case "datetime": {
|
4050
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
4051
|
+
break;
|
4052
|
+
}
|
4053
|
+
case `file`:
|
4054
|
+
result[key] = await parseInputFileEntry(value);
|
4055
|
+
break;
|
4056
|
+
case "file[]":
|
4057
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4058
|
+
break;
|
4059
|
+
case "json":
|
4060
|
+
result[key] = stringifyJson(value);
|
4061
|
+
break;
|
4062
|
+
default:
|
4063
|
+
result[key] = value;
|
4064
|
+
}
|
4065
|
+
}
|
4066
|
+
return result;
|
3762
4067
|
};
|
3763
4068
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
3764
4069
|
const data = {};
|
@@ -3790,18 +4095,33 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
3790
4095
|
if (item === column.name) {
|
3791
4096
|
return [...acc, "*"];
|
3792
4097
|
}
|
3793
|
-
if (item.startsWith(`${column.name}.`)) {
|
4098
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
3794
4099
|
const [, ...path] = item.split(".");
|
3795
4100
|
return [...acc, path.join(".")];
|
3796
4101
|
}
|
3797
4102
|
return acc;
|
3798
4103
|
}, []);
|
3799
|
-
data[column.name] = initObject(
|
4104
|
+
data[column.name] = initObject(
|
4105
|
+
db,
|
4106
|
+
schemaTables,
|
4107
|
+
linkTable,
|
4108
|
+
value,
|
4109
|
+
selectedLinkColumns
|
4110
|
+
);
|
3800
4111
|
} else {
|
3801
4112
|
data[column.name] = null;
|
3802
4113
|
}
|
3803
4114
|
break;
|
3804
4115
|
}
|
4116
|
+
case "file":
|
4117
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
4118
|
+
break;
|
4119
|
+
case "file[]":
|
4120
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4121
|
+
break;
|
4122
|
+
case "json":
|
4123
|
+
data[column.name] = parseJson(value);
|
4124
|
+
break;
|
3805
4125
|
default:
|
3806
4126
|
data[column.name] = value ?? null;
|
3807
4127
|
if (column.notNull === true && value === null) {
|
@@ -3811,33 +4131,34 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
3811
4131
|
}
|
3812
4132
|
}
|
3813
4133
|
const record = { ...data };
|
3814
|
-
const serializable = { xata, ...removeLinksFromObject(data) };
|
3815
4134
|
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
3816
4135
|
record.read = function(columns2) {
|
3817
4136
|
return db[table].read(record["id"], columns2);
|
3818
4137
|
};
|
3819
4138
|
record.update = function(data2, b, c) {
|
3820
|
-
const columns2 =
|
4139
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
3821
4140
|
const ifVersion = parseIfVersion(b, c);
|
3822
4141
|
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
3823
4142
|
};
|
3824
4143
|
record.replace = function(data2, b, c) {
|
3825
|
-
const columns2 =
|
4144
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
3826
4145
|
const ifVersion = parseIfVersion(b, c);
|
3827
4146
|
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
3828
4147
|
};
|
3829
4148
|
record.delete = function() {
|
3830
4149
|
return db[table].delete(record["id"]);
|
3831
4150
|
};
|
3832
|
-
|
4151
|
+
if (metadata !== void 0) {
|
4152
|
+
record.xata = Object.freeze(metadata);
|
4153
|
+
}
|
3833
4154
|
record.getMetadata = function() {
|
3834
4155
|
return record.xata;
|
3835
4156
|
};
|
3836
4157
|
record.toSerializable = function() {
|
3837
|
-
return JSON.parse(JSON.stringify(
|
4158
|
+
return JSON.parse(JSON.stringify(record));
|
3838
4159
|
};
|
3839
4160
|
record.toString = function() {
|
3840
|
-
return JSON.stringify(
|
4161
|
+
return JSON.stringify(record);
|
3841
4162
|
};
|
3842
4163
|
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
3843
4164
|
Object.defineProperty(record, prop, { enumerable: false });
|
@@ -3855,7 +4176,7 @@ function extractId(value) {
|
|
3855
4176
|
function isValidColumn(columns, column) {
|
3856
4177
|
if (columns.includes("*"))
|
3857
4178
|
return true;
|
3858
|
-
return columns.filter((item) => item.startsWith(column.name)).length > 0;
|
4179
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
3859
4180
|
}
|
3860
4181
|
function parseIfVersion(...args) {
|
3861
4182
|
for (const arg of args) {
|
@@ -3866,12 +4187,6 @@ function parseIfVersion(...args) {
|
|
3866
4187
|
return void 0;
|
3867
4188
|
}
|
3868
4189
|
|
3869
|
-
var __defProp$3 = Object.defineProperty;
|
3870
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
3871
|
-
var __publicField$3 = (obj, key, value) => {
|
3872
|
-
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
3873
|
-
return value;
|
3874
|
-
};
|
3875
4190
|
var __accessCheck$3 = (obj, member, msg) => {
|
3876
4191
|
if (!member.has(obj))
|
3877
4192
|
throw TypeError("Cannot " + msg);
|
@@ -3894,8 +4209,6 @@ var _map;
|
|
3894
4209
|
class SimpleCache {
|
3895
4210
|
constructor(options = {}) {
|
3896
4211
|
__privateAdd$3(this, _map, void 0);
|
3897
|
-
__publicField$3(this, "capacity");
|
3898
|
-
__publicField$3(this, "defaultQueryTTL");
|
3899
4212
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
3900
4213
|
this.capacity = options.max ?? 500;
|
3901
4214
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
@@ -3940,10 +4253,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
3940
4253
|
const startsWith = (value) => ({ $startsWith: value });
|
3941
4254
|
const endsWith = (value) => ({ $endsWith: value });
|
3942
4255
|
const pattern = (value) => ({ $pattern: value });
|
4256
|
+
const iPattern = (value) => ({ $iPattern: value });
|
3943
4257
|
const is = (value) => ({ $is: value });
|
3944
4258
|
const equals = is;
|
3945
4259
|
const isNot = (value) => ({ $isNot: value });
|
3946
4260
|
const contains = (value) => ({ $contains: value });
|
4261
|
+
const iContains = (value) => ({ $iContains: value });
|
3947
4262
|
const includes = (value) => ({ $includes: value });
|
3948
4263
|
const includesAll = (value) => ({ $includesAll: value });
|
3949
4264
|
const includesNone = (value) => ({ $includesNone: value });
|
@@ -3999,6 +4314,80 @@ class SchemaPlugin extends XataPlugin {
|
|
3999
4314
|
_tables = new WeakMap();
|
4000
4315
|
_schemaTables$1 = new WeakMap();
|
4001
4316
|
|
4317
|
+
class FilesPlugin extends XataPlugin {
|
4318
|
+
build(pluginOptions) {
|
4319
|
+
return {
|
4320
|
+
download: async (location) => {
|
4321
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4322
|
+
return await getFileItem({
|
4323
|
+
pathParams: {
|
4324
|
+
workspace: "{workspaceId}",
|
4325
|
+
dbBranchName: "{dbBranch}",
|
4326
|
+
region: "{region}",
|
4327
|
+
tableName: table ?? "",
|
4328
|
+
recordId: record ?? "",
|
4329
|
+
columnName: column ?? "",
|
4330
|
+
fileId
|
4331
|
+
},
|
4332
|
+
...pluginOptions,
|
4333
|
+
rawResponse: true
|
4334
|
+
});
|
4335
|
+
},
|
4336
|
+
upload: async (location, file, options) => {
|
4337
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4338
|
+
const resolvedFile = await file;
|
4339
|
+
const contentType = options?.mediaType || getContentType(resolvedFile);
|
4340
|
+
const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
|
4341
|
+
return await putFileItem({
|
4342
|
+
...pluginOptions,
|
4343
|
+
pathParams: {
|
4344
|
+
workspace: "{workspaceId}",
|
4345
|
+
dbBranchName: "{dbBranch}",
|
4346
|
+
region: "{region}",
|
4347
|
+
tableName: table ?? "",
|
4348
|
+
recordId: record ?? "",
|
4349
|
+
columnName: column ?? "",
|
4350
|
+
fileId
|
4351
|
+
},
|
4352
|
+
body,
|
4353
|
+
headers: { "Content-Type": contentType }
|
4354
|
+
});
|
4355
|
+
},
|
4356
|
+
delete: async (location) => {
|
4357
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4358
|
+
return await deleteFileItem({
|
4359
|
+
pathParams: {
|
4360
|
+
workspace: "{workspaceId}",
|
4361
|
+
dbBranchName: "{dbBranch}",
|
4362
|
+
region: "{region}",
|
4363
|
+
tableName: table ?? "",
|
4364
|
+
recordId: record ?? "",
|
4365
|
+
columnName: column ?? "",
|
4366
|
+
fileId
|
4367
|
+
},
|
4368
|
+
...pluginOptions
|
4369
|
+
});
|
4370
|
+
}
|
4371
|
+
};
|
4372
|
+
}
|
4373
|
+
}
|
4374
|
+
function getContentType(file) {
|
4375
|
+
if (typeof file === "string") {
|
4376
|
+
return "text/plain";
|
4377
|
+
}
|
4378
|
+
if ("mediaType" in file) {
|
4379
|
+
return file.mediaType;
|
4380
|
+
}
|
4381
|
+
if (isBlob(file)) {
|
4382
|
+
return file.type;
|
4383
|
+
}
|
4384
|
+
try {
|
4385
|
+
return file.type;
|
4386
|
+
} catch (e) {
|
4387
|
+
}
|
4388
|
+
return "application/octet-stream";
|
4389
|
+
}
|
4390
|
+
|
4002
4391
|
var __accessCheck$1 = (obj, member, msg) => {
|
4003
4392
|
if (!member.has(obj))
|
4004
4393
|
throw TypeError("Cannot " + msg);
|
@@ -4034,22 +4423,26 @@ class SearchPlugin extends XataPlugin {
|
|
4034
4423
|
build(pluginOptions) {
|
4035
4424
|
return {
|
4036
4425
|
all: async (query, options = {}) => {
|
4037
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4426
|
+
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4038
4427
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4039
|
-
return
|
4040
|
-
|
4041
|
-
|
4042
|
-
|
4428
|
+
return {
|
4429
|
+
totalCount,
|
4430
|
+
records: records.map((record) => {
|
4431
|
+
const { table = "orphan" } = record.xata;
|
4432
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
4433
|
+
})
|
4434
|
+
};
|
4043
4435
|
},
|
4044
4436
|
byTable: async (query, options = {}) => {
|
4045
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4437
|
+
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4046
4438
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4047
|
-
|
4439
|
+
const records = rawRecords.reduce((acc, record) => {
|
4048
4440
|
const { table = "orphan" } = record.xata;
|
4049
4441
|
const items = acc[table] ?? [];
|
4050
4442
|
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
4051
4443
|
return { ...acc, [table]: [...items, item] };
|
4052
4444
|
}, {});
|
4445
|
+
return { totalCount, records };
|
4053
4446
|
}
|
4054
4447
|
};
|
4055
4448
|
}
|
@@ -4058,13 +4451,13 @@ _schemaTables = new WeakMap();
|
|
4058
4451
|
_search = new WeakSet();
|
4059
4452
|
search_fn = async function(query, options, pluginOptions) {
|
4060
4453
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
4061
|
-
const { records } = await searchBranch({
|
4454
|
+
const { records, totalCount } = await searchBranch({
|
4062
4455
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4063
4456
|
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
4064
4457
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
4065
4458
|
...pluginOptions
|
4066
4459
|
});
|
4067
|
-
return records;
|
4460
|
+
return { records, totalCount };
|
4068
4461
|
};
|
4069
4462
|
_getSchemaTables = new WeakSet();
|
4070
4463
|
getSchemaTables_fn = async function(pluginOptions) {
|
@@ -4078,6 +4471,78 @@ getSchemaTables_fn = async function(pluginOptions) {
|
|
4078
4471
|
return schema.tables;
|
4079
4472
|
};
|
4080
4473
|
|
4474
|
+
function escapeElement(elementRepresentation) {
|
4475
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
4476
|
+
return '"' + escaped + '"';
|
4477
|
+
}
|
4478
|
+
function arrayString(val) {
|
4479
|
+
let result = "{";
|
4480
|
+
for (let i = 0; i < val.length; i++) {
|
4481
|
+
if (i > 0) {
|
4482
|
+
result = result + ",";
|
4483
|
+
}
|
4484
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
4485
|
+
result = result + "NULL";
|
4486
|
+
} else if (Array.isArray(val[i])) {
|
4487
|
+
result = result + arrayString(val[i]);
|
4488
|
+
} else if (val[i] instanceof Buffer) {
|
4489
|
+
result += "\\\\x" + val[i].toString("hex");
|
4490
|
+
} else {
|
4491
|
+
result += escapeElement(prepareValue(val[i]));
|
4492
|
+
}
|
4493
|
+
}
|
4494
|
+
result = result + "}";
|
4495
|
+
return result;
|
4496
|
+
}
|
4497
|
+
function prepareValue(value) {
|
4498
|
+
if (!isDefined(value))
|
4499
|
+
return null;
|
4500
|
+
if (value instanceof Date) {
|
4501
|
+
return value.toISOString();
|
4502
|
+
}
|
4503
|
+
if (Array.isArray(value)) {
|
4504
|
+
return arrayString(value);
|
4505
|
+
}
|
4506
|
+
if (isObject(value)) {
|
4507
|
+
return JSON.stringify(value);
|
4508
|
+
}
|
4509
|
+
try {
|
4510
|
+
return value.toString();
|
4511
|
+
} catch (e) {
|
4512
|
+
return value;
|
4513
|
+
}
|
4514
|
+
}
|
4515
|
+
function prepareParams(param1, param2) {
|
4516
|
+
if (isString(param1)) {
|
4517
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
4518
|
+
}
|
4519
|
+
if (isStringArray(param1)) {
|
4520
|
+
const statement = param1.reduce((acc, curr, index) => {
|
4521
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
4522
|
+
}, "");
|
4523
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
4524
|
+
}
|
4525
|
+
if (isObject(param1)) {
|
4526
|
+
const { statement, params, consistency } = param1;
|
4527
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
4528
|
+
}
|
4529
|
+
throw new Error("Invalid query");
|
4530
|
+
}
|
4531
|
+
|
4532
|
+
class SQLPlugin extends XataPlugin {
|
4533
|
+
build(pluginOptions) {
|
4534
|
+
return async (param1, ...param2) => {
|
4535
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
4536
|
+
const { records, warning } = await sqlQuery({
|
4537
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4538
|
+
body: { statement, params, consistency },
|
4539
|
+
...pluginOptions
|
4540
|
+
});
|
4541
|
+
return { records, warning };
|
4542
|
+
};
|
4543
|
+
}
|
4544
|
+
}
|
4545
|
+
|
4081
4546
|
class TransactionPlugin extends XataPlugin {
|
4082
4547
|
build(pluginOptions) {
|
4083
4548
|
return {
|
@@ -4093,12 +4558,6 @@ class TransactionPlugin extends XataPlugin {
|
|
4093
4558
|
}
|
4094
4559
|
}
|
4095
4560
|
|
4096
|
-
var __defProp$2 = Object.defineProperty;
|
4097
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4098
|
-
var __publicField$2 = (obj, key, value) => {
|
4099
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4100
|
-
return value;
|
4101
|
-
};
|
4102
4561
|
var __accessCheck = (obj, member, msg) => {
|
4103
4562
|
if (!member.has(obj))
|
4104
4563
|
throw TypeError("Cannot " + msg);
|
@@ -4128,9 +4587,6 @@ const buildClient = (plugins) => {
|
|
4128
4587
|
__privateAdd(this, _parseOptions);
|
4129
4588
|
__privateAdd(this, _getFetchProps);
|
4130
4589
|
__privateAdd(this, _options, void 0);
|
4131
|
-
__publicField$2(this, "db");
|
4132
|
-
__publicField$2(this, "search");
|
4133
|
-
__publicField$2(this, "transactions");
|
4134
4590
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
4135
4591
|
__privateSet(this, _options, safeOptions);
|
4136
4592
|
const pluginOptions = {
|
@@ -4141,9 +4597,13 @@ const buildClient = (plugins) => {
|
|
4141
4597
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
4142
4598
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
4143
4599
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4600
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
4601
|
+
const files = new FilesPlugin().build(pluginOptions);
|
4144
4602
|
this.db = db;
|
4145
4603
|
this.search = search;
|
4146
4604
|
this.transactions = transactions;
|
4605
|
+
this.sql = sql;
|
4606
|
+
this.files = files;
|
4147
4607
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
4148
4608
|
if (namespace === void 0)
|
4149
4609
|
continue;
|
@@ -4240,17 +4700,11 @@ const buildClient = (plugins) => {
|
|
4240
4700
|
class BaseClient extends buildClient() {
|
4241
4701
|
}
|
4242
4702
|
|
4243
|
-
var __defProp$1 = Object.defineProperty;
|
4244
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4245
|
-
var __publicField$1 = (obj, key, value) => {
|
4246
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4247
|
-
return value;
|
4248
|
-
};
|
4249
4703
|
const META = "__";
|
4250
4704
|
const VALUE = "___";
|
4251
4705
|
class Serializer {
|
4252
4706
|
constructor() {
|
4253
|
-
|
4707
|
+
this.classes = {};
|
4254
4708
|
}
|
4255
4709
|
add(clazz) {
|
4256
4710
|
this.classes[clazz.name] = clazz;
|
@@ -4313,34 +4767,12 @@ const deserialize = (json) => {
|
|
4313
4767
|
return defaultSerializer.fromJSON(json);
|
4314
4768
|
};
|
4315
4769
|
|
4316
|
-
function buildWorkerRunner(config) {
|
4317
|
-
return function xataWorker(name, worker) {
|
4318
|
-
return async (...args) => {
|
4319
|
-
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
4320
|
-
const result = await fetch(url, {
|
4321
|
-
method: "POST",
|
4322
|
-
headers: { "Content-Type": "application/json" },
|
4323
|
-
body: serialize({ args })
|
4324
|
-
});
|
4325
|
-
const text = await result.text();
|
4326
|
-
return deserialize(text);
|
4327
|
-
};
|
4328
|
-
};
|
4329
|
-
}
|
4330
|
-
|
4331
|
-
var __defProp = Object.defineProperty;
|
4332
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4333
|
-
var __publicField = (obj, key, value) => {
|
4334
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4335
|
-
return value;
|
4336
|
-
};
|
4337
4770
|
class XataError extends Error {
|
4338
4771
|
constructor(message, status) {
|
4339
4772
|
super(message);
|
4340
|
-
__publicField(this, "status");
|
4341
4773
|
this.status = status;
|
4342
4774
|
}
|
4343
4775
|
}
|
4344
4776
|
|
4345
|
-
export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, askTable, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString,
|
4777
|
+
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, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, 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, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, pgRollStatus, 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 };
|
4346
4778
|
//# sourceMappingURL=index.mjs.map
|