@xata.io/client 0.0.0-alpha.vfc446ea → 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 -4
- package/CHANGELOG.md +98 -2
- package/dist/index.cjs +324 -268
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +592 -146
- package/dist/index.mjs +312 -268
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -20,7 +20,8 @@ const TraceAttributes = {
|
|
20
20
|
HTTP_METHOD: "http.method",
|
21
21
|
HTTP_URL: "http.url",
|
22
22
|
HTTP_ROUTE: "http.route",
|
23
|
-
HTTP_TARGET: "http.target"
|
23
|
+
HTTP_TARGET: "http.target",
|
24
|
+
CLOUDFLARE_RAY_ID: "cf.ray"
|
24
25
|
};
|
25
26
|
|
26
27
|
function notEmpty(value) {
|
@@ -32,8 +33,15 @@ function compact(arr) {
|
|
32
33
|
function compactObject(obj) {
|
33
34
|
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
34
35
|
}
|
36
|
+
function isBlob(value) {
|
37
|
+
try {
|
38
|
+
return value instanceof Blob;
|
39
|
+
} catch (error) {
|
40
|
+
return false;
|
41
|
+
}
|
42
|
+
}
|
35
43
|
function isObject(value) {
|
36
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
|
44
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
37
45
|
}
|
38
46
|
function isDefined(value) {
|
39
47
|
return value !== null && value !== void 0;
|
@@ -236,12 +244,6 @@ function getPreviewBranch() {
|
|
236
244
|
}
|
237
245
|
}
|
238
246
|
|
239
|
-
var __defProp$8 = Object.defineProperty;
|
240
|
-
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
241
|
-
var __publicField$8 = (obj, key, value) => {
|
242
|
-
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
243
|
-
return value;
|
244
|
-
};
|
245
247
|
var __accessCheck$8 = (obj, member, msg) => {
|
246
248
|
if (!member.has(obj))
|
247
249
|
throw TypeError("Cannot " + msg);
|
@@ -265,14 +267,13 @@ var __privateMethod$4 = (obj, member, method) => {
|
|
265
267
|
return method;
|
266
268
|
};
|
267
269
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
268
|
-
const REQUEST_TIMEOUT =
|
270
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
269
271
|
function getFetchImplementation(userFetch) {
|
270
272
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
271
|
-
const
|
273
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
274
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
272
275
|
if (!fetchImpl) {
|
273
|
-
throw new Error(
|
274
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
275
|
-
);
|
276
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
276
277
|
}
|
277
278
|
return fetchImpl;
|
278
279
|
}
|
@@ -282,8 +283,6 @@ class ApiRequestPool {
|
|
282
283
|
__privateAdd$8(this, _fetch, void 0);
|
283
284
|
__privateAdd$8(this, _queue, void 0);
|
284
285
|
__privateAdd$8(this, _concurrency, void 0);
|
285
|
-
__publicField$8(this, "running");
|
286
|
-
__publicField$8(this, "started");
|
287
286
|
__privateSet$8(this, _queue, []);
|
288
287
|
__privateSet$8(this, _concurrency, concurrency);
|
289
288
|
this.running = 0;
|
@@ -529,26 +528,16 @@ function defaultOnOpen(response) {
|
|
529
528
|
}
|
530
529
|
}
|
531
530
|
|
532
|
-
const VERSION = "0.
|
531
|
+
const VERSION = "0.27.0";
|
533
532
|
|
534
|
-
var __defProp$7 = Object.defineProperty;
|
535
|
-
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
536
|
-
var __publicField$7 = (obj, key, value) => {
|
537
|
-
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
538
|
-
return value;
|
539
|
-
};
|
540
533
|
class ErrorWithCause extends Error {
|
541
534
|
constructor(message, options) {
|
542
535
|
super(message, options);
|
543
|
-
__publicField$7(this, "cause");
|
544
536
|
}
|
545
537
|
}
|
546
538
|
class FetcherError extends ErrorWithCause {
|
547
539
|
constructor(status, data, requestId) {
|
548
540
|
super(getMessage(data));
|
549
|
-
__publicField$7(this, "status");
|
550
|
-
__publicField$7(this, "requestId");
|
551
|
-
__publicField$7(this, "errors");
|
552
541
|
this.status = status;
|
553
542
|
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
554
543
|
this.requestId = requestId;
|
@@ -615,11 +604,14 @@ function hostHeader(url) {
|
|
615
604
|
const { groups } = pattern.exec(url) ?? {};
|
616
605
|
return groups?.host ? { Host: groups.host } : {};
|
617
606
|
}
|
618
|
-
function parseBody(body, headers) {
|
607
|
+
async function parseBody(body, headers) {
|
619
608
|
if (!isDefined(body))
|
620
609
|
return void 0;
|
610
|
+
if (isBlob(body) || typeof body.text === "function") {
|
611
|
+
return body;
|
612
|
+
}
|
621
613
|
const { "Content-Type": contentType } = headers ?? {};
|
622
|
-
if (String(contentType).toLowerCase() === "application/json") {
|
614
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
623
615
|
return JSON.stringify(body);
|
624
616
|
}
|
625
617
|
return body;
|
@@ -676,7 +668,7 @@ async function fetch$1({
|
|
676
668
|
const response = await pool.request(url, {
|
677
669
|
...fetchOptions,
|
678
670
|
method: method.toUpperCase(),
|
679
|
-
body: parseBody(body, headers),
|
671
|
+
body: await parseBody(body, headers),
|
680
672
|
headers,
|
681
673
|
signal
|
682
674
|
});
|
@@ -687,7 +679,8 @@ async function fetch$1({
|
|
687
679
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
688
680
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
689
681
|
[TraceAttributes.HTTP_HOST]: host,
|
690
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
682
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
683
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
691
684
|
});
|
692
685
|
const message = response.headers?.get("x-xata-message");
|
693
686
|
if (message)
|
@@ -775,6 +768,18 @@ function parseUrl(url) {
|
|
775
768
|
|
776
769
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
777
770
|
|
771
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({
|
772
|
+
url: "/db/{dbBranchName}/pgroll/apply",
|
773
|
+
method: "post",
|
774
|
+
...variables,
|
775
|
+
signal
|
776
|
+
});
|
777
|
+
const pgRollStatus = (variables, signal) => dataPlaneFetch({
|
778
|
+
url: "/db/{dbBranchName}/pgroll/status",
|
779
|
+
method: "get",
|
780
|
+
...variables,
|
781
|
+
signal
|
782
|
+
});
|
778
783
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
779
784
|
url: "/dbs/{dbName}",
|
780
785
|
method: "get",
|
@@ -794,6 +799,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
794
799
|
...variables,
|
795
800
|
signal
|
796
801
|
});
|
802
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
803
|
+
url: "/db/{dbBranchName}/schema",
|
804
|
+
method: "get",
|
805
|
+
...variables,
|
806
|
+
signal
|
807
|
+
});
|
797
808
|
const copyBranch = (variables, signal) => dataPlaneFetch({
|
798
809
|
url: "/db/{dbBranchName}/copy",
|
799
810
|
method: "post",
|
@@ -983,6 +994,8 @@ const sqlQuery = (variables, signal) => dataPlaneFetch({
|
|
983
994
|
});
|
984
995
|
const operationsByTag$2 = {
|
985
996
|
branch: {
|
997
|
+
applyMigration,
|
998
|
+
pgRollStatus,
|
986
999
|
getBranchList,
|
987
1000
|
getBranchDetails,
|
988
1001
|
createBranch,
|
@@ -997,6 +1010,7 @@ const operationsByTag$2 = {
|
|
997
1010
|
resolveBranch
|
998
1011
|
},
|
999
1012
|
migrations: {
|
1013
|
+
getSchema,
|
1000
1014
|
getBranchMigrationHistory,
|
1001
1015
|
getBranchMigrationPlan,
|
1002
1016
|
executeBranchMigrationPlan,
|
@@ -1100,6 +1114,12 @@ const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
|
1100
1114
|
...variables,
|
1101
1115
|
signal
|
1102
1116
|
});
|
1117
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1118
|
+
url: "/user/oauth/clients/{clientId}",
|
1119
|
+
method: "delete",
|
1120
|
+
...variables,
|
1121
|
+
signal
|
1122
|
+
});
|
1103
1123
|
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1104
1124
|
url: "/user/oauth/tokens",
|
1105
1125
|
method: "get",
|
@@ -1156,6 +1176,20 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
|
|
1156
1176
|
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
1157
1177
|
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
1158
1178
|
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1179
|
+
const listClusters = (variables, signal) => controlPlaneFetch({
|
1180
|
+
url: "/workspaces/{workspaceId}/clusters",
|
1181
|
+
method: "get",
|
1182
|
+
...variables,
|
1183
|
+
signal
|
1184
|
+
});
|
1185
|
+
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
1186
|
+
const getCluster = (variables, signal) => controlPlaneFetch({
|
1187
|
+
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
1188
|
+
method: "get",
|
1189
|
+
...variables,
|
1190
|
+
signal
|
1191
|
+
});
|
1192
|
+
const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
|
1159
1193
|
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
1160
1194
|
url: "/workspaces/{workspaceId}/dbs",
|
1161
1195
|
method: "get",
|
@@ -1182,9 +1216,17 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
1182
1216
|
signal
|
1183
1217
|
});
|
1184
1218
|
const operationsByTag$1 = {
|
1185
|
-
|
1219
|
+
oAuth: {
|
1220
|
+
getAuthorizationCode,
|
1221
|
+
grantAuthorizationCode,
|
1222
|
+
getUserOAuthClients,
|
1223
|
+
deleteUserOAuthClient,
|
1224
|
+
getUserOAuthAccessTokens,
|
1225
|
+
deleteOAuthAccessToken,
|
1226
|
+
updateOAuthAccessToken
|
1227
|
+
},
|
1186
1228
|
users: { getUser, updateUser, deleteUser },
|
1187
|
-
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey
|
1229
|
+
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
1188
1230
|
workspaces: {
|
1189
1231
|
getWorkspacesList,
|
1190
1232
|
createWorkspace,
|
@@ -1202,6 +1244,7 @@ const operationsByTag$1 = {
|
|
1202
1244
|
acceptWorkspaceMemberInvite,
|
1203
1245
|
resendWorkspaceMemberInvite
|
1204
1246
|
},
|
1247
|
+
xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
|
1205
1248
|
databases: {
|
1206
1249
|
getDatabaseList,
|
1207
1250
|
createDatabase,
|
@@ -2597,60 +2640,6 @@ class XataApiPlugin {
|
|
2597
2640
|
class XataPlugin {
|
2598
2641
|
}
|
2599
2642
|
|
2600
|
-
class FilesPlugin extends XataPlugin {
|
2601
|
-
build(pluginOptions) {
|
2602
|
-
return {
|
2603
|
-
download: async (location) => {
|
2604
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2605
|
-
return await getFileItem({
|
2606
|
-
pathParams: {
|
2607
|
-
workspace: "{workspaceId}",
|
2608
|
-
dbBranchName: "{dbBranch}",
|
2609
|
-
region: "{region}",
|
2610
|
-
tableName: table ?? "",
|
2611
|
-
recordId: record ?? "",
|
2612
|
-
columnName: column ?? "",
|
2613
|
-
fileId
|
2614
|
-
},
|
2615
|
-
...pluginOptions,
|
2616
|
-
rawResponse: true
|
2617
|
-
});
|
2618
|
-
},
|
2619
|
-
upload: async (location, file) => {
|
2620
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2621
|
-
return await putFileItem({
|
2622
|
-
pathParams: {
|
2623
|
-
workspace: "{workspaceId}",
|
2624
|
-
dbBranchName: "{dbBranch}",
|
2625
|
-
region: "{region}",
|
2626
|
-
tableName: table ?? "",
|
2627
|
-
recordId: record ?? "",
|
2628
|
-
columnName: column ?? "",
|
2629
|
-
fileId
|
2630
|
-
},
|
2631
|
-
body: file,
|
2632
|
-
...pluginOptions
|
2633
|
-
});
|
2634
|
-
},
|
2635
|
-
delete: async (location) => {
|
2636
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2637
|
-
return await deleteFileItem({
|
2638
|
-
pathParams: {
|
2639
|
-
workspace: "{workspaceId}",
|
2640
|
-
dbBranchName: "{dbBranch}",
|
2641
|
-
region: "{region}",
|
2642
|
-
tableName: table ?? "",
|
2643
|
-
recordId: record ?? "",
|
2644
|
-
columnName: column ?? "",
|
2645
|
-
fileId
|
2646
|
-
},
|
2647
|
-
...pluginOptions
|
2648
|
-
});
|
2649
|
-
}
|
2650
|
-
};
|
2651
|
-
}
|
2652
|
-
}
|
2653
|
-
|
2654
2643
|
function buildTransformString(transformations) {
|
2655
2644
|
return transformations.flatMap(
|
2656
2645
|
(t) => Object.entries(t).map(([key, value]) => {
|
@@ -2666,72 +2655,32 @@ function buildTransformString(transformations) {
|
|
2666
2655
|
})
|
2667
2656
|
).join(",");
|
2668
2657
|
}
|
2669
|
-
function transformImage(url, transformations) {
|
2658
|
+
function transformImage(url, ...transformations) {
|
2670
2659
|
if (!isDefined(url))
|
2671
2660
|
return void 0;
|
2672
|
-
const
|
2661
|
+
const newTransformations = buildTransformString(transformations);
|
2673
2662
|
const { hostname, pathname, search } = new URL(url);
|
2674
|
-
|
2663
|
+
const pathParts = pathname.split("/");
|
2664
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
2665
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
2666
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
2667
|
+
const path = pathParts.join("/");
|
2668
|
+
return `https://${hostname}${transform}${path}${search}`;
|
2675
2669
|
}
|
2676
2670
|
|
2677
|
-
var __defProp$6 = Object.defineProperty;
|
2678
|
-
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2679
|
-
var __publicField$6 = (obj, key, value) => {
|
2680
|
-
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2681
|
-
return value;
|
2682
|
-
};
|
2683
2671
|
class XataFile {
|
2684
2672
|
constructor(file) {
|
2685
|
-
|
2686
|
-
|
2687
|
-
*/
|
2688
|
-
__publicField$6(this, "name");
|
2689
|
-
/**
|
2690
|
-
* Media type of this file.
|
2691
|
-
*/
|
2692
|
-
__publicField$6(this, "mediaType");
|
2693
|
-
/**
|
2694
|
-
* Base64 encoded content of this file.
|
2695
|
-
*/
|
2696
|
-
__publicField$6(this, "base64Content");
|
2697
|
-
/**
|
2698
|
-
* Whether to enable public url for this file.
|
2699
|
-
*/
|
2700
|
-
__publicField$6(this, "enablePublicUrl");
|
2701
|
-
/**
|
2702
|
-
* Timeout for the signed url.
|
2703
|
-
*/
|
2704
|
-
__publicField$6(this, "signedUrlTimeout");
|
2705
|
-
/**
|
2706
|
-
* Size of this file.
|
2707
|
-
*/
|
2708
|
-
__publicField$6(this, "size");
|
2709
|
-
/**
|
2710
|
-
* Version of this file.
|
2711
|
-
*/
|
2712
|
-
__publicField$6(this, "version");
|
2713
|
-
/**
|
2714
|
-
* Url of this file.
|
2715
|
-
*/
|
2716
|
-
__publicField$6(this, "url");
|
2717
|
-
/**
|
2718
|
-
* Signed url of this file.
|
2719
|
-
*/
|
2720
|
-
__publicField$6(this, "signedUrl");
|
2721
|
-
/**
|
2722
|
-
* Attributes of this file.
|
2723
|
-
*/
|
2724
|
-
__publicField$6(this, "attributes");
|
2725
|
-
this.name = file.name;
|
2673
|
+
this.id = file.id;
|
2674
|
+
this.name = file.name || "";
|
2726
2675
|
this.mediaType = file.mediaType || "application/octet-stream";
|
2727
2676
|
this.base64Content = file.base64Content;
|
2728
|
-
this.enablePublicUrl = file.enablePublicUrl;
|
2729
|
-
this.signedUrlTimeout = file.signedUrlTimeout;
|
2730
|
-
this.size = file.size;
|
2731
|
-
this.version = file.version;
|
2732
|
-
this.url = file.url;
|
2677
|
+
this.enablePublicUrl = file.enablePublicUrl ?? false;
|
2678
|
+
this.signedUrlTimeout = file.signedUrlTimeout ?? 300;
|
2679
|
+
this.size = file.size ?? 0;
|
2680
|
+
this.version = file.version ?? 1;
|
2681
|
+
this.url = file.url || "";
|
2733
2682
|
this.signedUrl = file.signedUrl;
|
2734
|
-
this.attributes = file.attributes;
|
2683
|
+
this.attributes = file.attributes || {};
|
2735
2684
|
}
|
2736
2685
|
static fromBuffer(buffer, options = {}) {
|
2737
2686
|
const base64Content = buffer.toString("base64");
|
@@ -2783,8 +2732,12 @@ class XataFile {
|
|
2783
2732
|
if (!this.base64Content) {
|
2784
2733
|
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2785
2734
|
}
|
2786
|
-
const
|
2787
|
-
|
2735
|
+
const binary = atob(this.base64Content);
|
2736
|
+
const uint8Array = new Uint8Array(binary.length);
|
2737
|
+
for (let i = 0; i < binary.length; i++) {
|
2738
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2739
|
+
}
|
2740
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
2788
2741
|
}
|
2789
2742
|
static fromString(string, options = {}) {
|
2790
2743
|
const base64Content = btoa(string);
|
@@ -2807,8 +2760,10 @@ class XataFile {
|
|
2807
2760
|
}
|
2808
2761
|
transform(...options) {
|
2809
2762
|
return {
|
2810
|
-
url: transformImage(this.url, options),
|
2811
|
-
signedUrl: transformImage(this.signedUrl, options)
|
2763
|
+
url: transformImage(this.url, ...options),
|
2764
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
2765
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
2766
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
2812
2767
|
};
|
2813
2768
|
}
|
2814
2769
|
}
|
@@ -2816,7 +2771,15 @@ const parseInputFileEntry = async (entry) => {
|
|
2816
2771
|
if (!isDefined(entry))
|
2817
2772
|
return null;
|
2818
2773
|
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2819
|
-
return compactObject({
|
2774
|
+
return compactObject({
|
2775
|
+
id,
|
2776
|
+
// Name cannot be an empty string in our API
|
2777
|
+
name: name ? name : void 0,
|
2778
|
+
mediaType,
|
2779
|
+
base64Content,
|
2780
|
+
enablePublicUrl,
|
2781
|
+
signedUrlTimeout
|
2782
|
+
});
|
2820
2783
|
};
|
2821
2784
|
|
2822
2785
|
function cleanFilter(filter) {
|
@@ -2846,12 +2809,25 @@ function cleanFilter(filter) {
|
|
2846
2809
|
return Object.keys(values).length > 0 ? values : void 0;
|
2847
2810
|
}
|
2848
2811
|
|
2849
|
-
|
2850
|
-
|
2851
|
-
|
2852
|
-
|
2853
|
-
|
2854
|
-
|
2812
|
+
function stringifyJson(value) {
|
2813
|
+
if (!isDefined(value))
|
2814
|
+
return value;
|
2815
|
+
if (isString(value))
|
2816
|
+
return value;
|
2817
|
+
try {
|
2818
|
+
return JSON.stringify(value);
|
2819
|
+
} catch (e) {
|
2820
|
+
return value;
|
2821
|
+
}
|
2822
|
+
}
|
2823
|
+
function parseJson(value) {
|
2824
|
+
try {
|
2825
|
+
return JSON.parse(value);
|
2826
|
+
} catch (e) {
|
2827
|
+
return value;
|
2828
|
+
}
|
2829
|
+
}
|
2830
|
+
|
2855
2831
|
var __accessCheck$6 = (obj, member, msg) => {
|
2856
2832
|
if (!member.has(obj))
|
2857
2833
|
throw TypeError("Cannot " + msg);
|
@@ -2874,14 +2850,6 @@ var _query, _page;
|
|
2874
2850
|
class Page {
|
2875
2851
|
constructor(query, meta, records = []) {
|
2876
2852
|
__privateAdd$6(this, _query, void 0);
|
2877
|
-
/**
|
2878
|
-
* Page metadata, required to retrieve additional records.
|
2879
|
-
*/
|
2880
|
-
__publicField$5(this, "meta");
|
2881
|
-
/**
|
2882
|
-
* The set of results for this page.
|
2883
|
-
*/
|
2884
|
-
__publicField$5(this, "records");
|
2885
2853
|
__privateSet$6(this, _query, query);
|
2886
2854
|
this.meta = meta;
|
2887
2855
|
this.records = new RecordArray(this, records);
|
@@ -2931,9 +2899,9 @@ class Page {
|
|
2931
2899
|
}
|
2932
2900
|
}
|
2933
2901
|
_query = new WeakMap();
|
2934
|
-
const PAGINATION_MAX_SIZE =
|
2902
|
+
const PAGINATION_MAX_SIZE = 1e3;
|
2935
2903
|
const PAGINATION_DEFAULT_SIZE = 20;
|
2936
|
-
const PAGINATION_MAX_OFFSET =
|
2904
|
+
const PAGINATION_MAX_OFFSET = 49e3;
|
2937
2905
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
2938
2906
|
function isCursorPaginationOptions(options) {
|
2939
2907
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
@@ -3012,12 +2980,6 @@ const _RecordArray = class _RecordArray extends Array {
|
|
3012
2980
|
_page = new WeakMap();
|
3013
2981
|
let RecordArray = _RecordArray;
|
3014
2982
|
|
3015
|
-
var __defProp$4 = Object.defineProperty;
|
3016
|
-
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
3017
|
-
var __publicField$4 = (obj, key, value) => {
|
3018
|
-
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
3019
|
-
return value;
|
3020
|
-
};
|
3021
2983
|
var __accessCheck$5 = (obj, member, msg) => {
|
3022
2984
|
if (!member.has(obj))
|
3023
2985
|
throw TypeError("Cannot " + msg);
|
@@ -3048,8 +3010,8 @@ const _Query = class _Query {
|
|
3048
3010
|
__privateAdd$5(this, _repository, void 0);
|
3049
3011
|
__privateAdd$5(this, _data, { filter: {} });
|
3050
3012
|
// Implements pagination
|
3051
|
-
|
3052
|
-
|
3013
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
3014
|
+
this.records = new RecordArray(this, []);
|
3053
3015
|
__privateSet$5(this, _table$1, table);
|
3054
3016
|
if (repository) {
|
3055
3017
|
__privateSet$5(this, _repository, repository);
|
@@ -3304,7 +3266,8 @@ const RecordColumnTypes = [
|
|
3304
3266
|
"datetime",
|
3305
3267
|
"vector",
|
3306
3268
|
"file[]",
|
3307
|
-
"file"
|
3269
|
+
"file",
|
3270
|
+
"json"
|
3308
3271
|
];
|
3309
3272
|
function isIdentifiable(x) {
|
3310
3273
|
return isObject(x) && isString(x?.id);
|
@@ -3315,6 +3278,24 @@ function isXataRecord(x) {
|
|
3315
3278
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
3316
3279
|
}
|
3317
3280
|
|
3281
|
+
function isValidExpandedColumn(column) {
|
3282
|
+
return isObject(column) && isString(column.name);
|
3283
|
+
}
|
3284
|
+
function isValidSelectableColumns(columns) {
|
3285
|
+
if (!Array.isArray(columns)) {
|
3286
|
+
return false;
|
3287
|
+
}
|
3288
|
+
return columns.every((column) => {
|
3289
|
+
if (typeof column === "string") {
|
3290
|
+
return true;
|
3291
|
+
}
|
3292
|
+
if (typeof column === "object") {
|
3293
|
+
return isValidExpandedColumn(column);
|
3294
|
+
}
|
3295
|
+
return false;
|
3296
|
+
});
|
3297
|
+
}
|
3298
|
+
|
3318
3299
|
function isSortFilterString(value) {
|
3319
3300
|
return isString(value);
|
3320
3301
|
}
|
@@ -3415,24 +3396,24 @@ class RestRepository extends Query {
|
|
3415
3396
|
if (a.length === 0)
|
3416
3397
|
return [];
|
3417
3398
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
3418
|
-
const columns =
|
3399
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3419
3400
|
const result = await this.read(ids, columns);
|
3420
3401
|
return result;
|
3421
3402
|
}
|
3422
3403
|
if (isString(a) && isObject(b)) {
|
3423
3404
|
if (a === "")
|
3424
3405
|
throw new Error("The id can't be empty");
|
3425
|
-
const columns =
|
3406
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3426
3407
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
3427
3408
|
}
|
3428
3409
|
if (isObject(a) && isString(a.id)) {
|
3429
3410
|
if (a.id === "")
|
3430
3411
|
throw new Error("The id can't be empty");
|
3431
|
-
const columns =
|
3412
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3432
3413
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
3433
3414
|
}
|
3434
3415
|
if (isObject(a)) {
|
3435
|
-
const columns =
|
3416
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3436
3417
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
3437
3418
|
}
|
3438
3419
|
throw new Error("Invalid arguments for create method");
|
@@ -3440,7 +3421,7 @@ class RestRepository extends Query {
|
|
3440
3421
|
}
|
3441
3422
|
async read(a, b) {
|
3442
3423
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
3443
|
-
const columns =
|
3424
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3444
3425
|
if (Array.isArray(a)) {
|
3445
3426
|
if (a.length === 0)
|
3446
3427
|
return [];
|
@@ -3467,7 +3448,13 @@ class RestRepository extends Query {
|
|
3467
3448
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3468
3449
|
});
|
3469
3450
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3470
|
-
return initObject(
|
3451
|
+
return initObject(
|
3452
|
+
__privateGet$4(this, _db),
|
3453
|
+
schemaTables,
|
3454
|
+
__privateGet$4(this, _table),
|
3455
|
+
response,
|
3456
|
+
columns
|
3457
|
+
);
|
3471
3458
|
} catch (e) {
|
3472
3459
|
if (isObject(e) && e.status === 404) {
|
3473
3460
|
return null;
|
@@ -3509,17 +3496,17 @@ class RestRepository extends Query {
|
|
3509
3496
|
ifVersion,
|
3510
3497
|
upsert: false
|
3511
3498
|
});
|
3512
|
-
const columns =
|
3499
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3513
3500
|
const result = await this.read(a, columns);
|
3514
3501
|
return result;
|
3515
3502
|
}
|
3516
3503
|
try {
|
3517
3504
|
if (isString(a) && isObject(b)) {
|
3518
|
-
const columns =
|
3505
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3519
3506
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3520
3507
|
}
|
3521
3508
|
if (isObject(a) && isString(a.id)) {
|
3522
|
-
const columns =
|
3509
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3523
3510
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3524
3511
|
}
|
3525
3512
|
} catch (error) {
|
@@ -3559,20 +3546,20 @@ class RestRepository extends Query {
|
|
3559
3546
|
ifVersion,
|
3560
3547
|
upsert: true
|
3561
3548
|
});
|
3562
|
-
const columns =
|
3549
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3563
3550
|
const result = await this.read(a, columns);
|
3564
3551
|
return result;
|
3565
3552
|
}
|
3566
3553
|
if (isString(a) && isObject(b)) {
|
3567
3554
|
if (a === "")
|
3568
3555
|
throw new Error("The id can't be empty");
|
3569
|
-
const columns =
|
3556
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3570
3557
|
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3571
3558
|
}
|
3572
3559
|
if (isObject(a) && isString(a.id)) {
|
3573
3560
|
if (a.id === "")
|
3574
3561
|
throw new Error("The id can't be empty");
|
3575
|
-
const columns =
|
3562
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3576
3563
|
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3577
3564
|
}
|
3578
3565
|
if (!isDefined(a) && isObject(b)) {
|
@@ -3591,20 +3578,20 @@ class RestRepository extends Query {
|
|
3591
3578
|
if (a.length === 0)
|
3592
3579
|
return [];
|
3593
3580
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
3594
|
-
const columns =
|
3581
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3595
3582
|
const result = await this.read(ids, columns);
|
3596
3583
|
return result;
|
3597
3584
|
}
|
3598
3585
|
if (isString(a) && isObject(b)) {
|
3599
3586
|
if (a === "")
|
3600
3587
|
throw new Error("The id can't be empty");
|
3601
|
-
const columns =
|
3588
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3602
3589
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3603
3590
|
}
|
3604
3591
|
if (isObject(a) && isString(a.id)) {
|
3605
3592
|
if (a.id === "")
|
3606
3593
|
throw new Error("The id can't be empty");
|
3607
|
-
const columns =
|
3594
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3608
3595
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3609
3596
|
}
|
3610
3597
|
if (!isDefined(a) && isObject(b)) {
|
@@ -3628,7 +3615,7 @@ class RestRepository extends Query {
|
|
3628
3615
|
return o.id;
|
3629
3616
|
throw new Error("Invalid arguments for delete method");
|
3630
3617
|
});
|
3631
|
-
const columns =
|
3618
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3632
3619
|
const result = await this.read(a, columns);
|
3633
3620
|
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
3634
3621
|
return result;
|
@@ -3662,7 +3649,7 @@ class RestRepository extends Query {
|
|
3662
3649
|
}
|
3663
3650
|
async search(query, options = {}) {
|
3664
3651
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
3665
|
-
const { records } = await searchTable({
|
3652
|
+
const { records, totalCount } = await searchTable({
|
3666
3653
|
pathParams: {
|
3667
3654
|
workspace: "{workspaceId}",
|
3668
3655
|
dbBranchName: "{dbBranch}",
|
@@ -3682,12 +3669,15 @@ class RestRepository extends Query {
|
|
3682
3669
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3683
3670
|
});
|
3684
3671
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3685
|
-
return
|
3672
|
+
return {
|
3673
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3674
|
+
totalCount
|
3675
|
+
};
|
3686
3676
|
});
|
3687
3677
|
}
|
3688
3678
|
async vectorSearch(column, query, options) {
|
3689
3679
|
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3690
|
-
const { records } = await vectorSearchTable({
|
3680
|
+
const { records, totalCount } = await vectorSearchTable({
|
3691
3681
|
pathParams: {
|
3692
3682
|
workspace: "{workspaceId}",
|
3693
3683
|
dbBranchName: "{dbBranch}",
|
@@ -3704,7 +3694,10 @@ class RestRepository extends Query {
|
|
3704
3694
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3705
3695
|
});
|
3706
3696
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3707
|
-
return
|
3697
|
+
return {
|
3698
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3699
|
+
totalCount
|
3700
|
+
};
|
3708
3701
|
});
|
3709
3702
|
}
|
3710
3703
|
async aggregate(aggs, filter) {
|
@@ -3747,7 +3740,13 @@ class RestRepository extends Query {
|
|
3747
3740
|
});
|
3748
3741
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3749
3742
|
const records = objects.map(
|
3750
|
-
(record) => initObject(
|
3743
|
+
(record) => initObject(
|
3744
|
+
__privateGet$4(this, _db),
|
3745
|
+
schemaTables,
|
3746
|
+
__privateGet$4(this, _table),
|
3747
|
+
record,
|
3748
|
+
data.columns ?? ["*"]
|
3749
|
+
)
|
3751
3750
|
);
|
3752
3751
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
3753
3752
|
return new Page(query, meta, records);
|
@@ -3774,7 +3773,13 @@ class RestRepository extends Query {
|
|
3774
3773
|
},
|
3775
3774
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3776
3775
|
});
|
3777
|
-
|
3776
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3777
|
+
return {
|
3778
|
+
...result,
|
3779
|
+
summaries: result.summaries.map(
|
3780
|
+
(summary) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), summary, data.columns ?? [])
|
3781
|
+
)
|
3782
|
+
};
|
3778
3783
|
});
|
3779
3784
|
}
|
3780
3785
|
ask(question, options) {
|
@@ -4053,19 +4058,15 @@ transformObjectToApi_fn = async function(object) {
|
|
4053
4058
|
case "file[]":
|
4054
4059
|
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4055
4060
|
break;
|
4061
|
+
case "json":
|
4062
|
+
result[key] = stringifyJson(value);
|
4063
|
+
break;
|
4056
4064
|
default:
|
4057
4065
|
result[key] = value;
|
4058
4066
|
}
|
4059
4067
|
}
|
4060
4068
|
return result;
|
4061
4069
|
};
|
4062
|
-
const removeLinksFromObject = (object) => {
|
4063
|
-
return Object.entries(object).reduce((acc, [key, value]) => {
|
4064
|
-
if (key === "xata")
|
4065
|
-
return acc;
|
4066
|
-
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
4067
|
-
}, {});
|
4068
|
-
};
|
4069
4070
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
4070
4071
|
const data = {};
|
4071
4072
|
const { xata, ...rest } = object ?? {};
|
@@ -4096,13 +4097,19 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4096
4097
|
if (item === column.name) {
|
4097
4098
|
return [...acc, "*"];
|
4098
4099
|
}
|
4099
|
-
if (item.startsWith(`${column.name}.`)) {
|
4100
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
4100
4101
|
const [, ...path] = item.split(".");
|
4101
4102
|
return [...acc, path.join(".")];
|
4102
4103
|
}
|
4103
4104
|
return acc;
|
4104
4105
|
}, []);
|
4105
|
-
data[column.name] = initObject(
|
4106
|
+
data[column.name] = initObject(
|
4107
|
+
db,
|
4108
|
+
schemaTables,
|
4109
|
+
linkTable,
|
4110
|
+
value,
|
4111
|
+
selectedLinkColumns
|
4112
|
+
);
|
4106
4113
|
} else {
|
4107
4114
|
data[column.name] = null;
|
4108
4115
|
}
|
@@ -4114,6 +4121,9 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4114
4121
|
case "file[]":
|
4115
4122
|
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4116
4123
|
break;
|
4124
|
+
case "json":
|
4125
|
+
data[column.name] = parseJson(value);
|
4126
|
+
break;
|
4117
4127
|
default:
|
4118
4128
|
data[column.name] = value ?? null;
|
4119
4129
|
if (column.notNull === true && value === null) {
|
@@ -4123,33 +4133,34 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4123
4133
|
}
|
4124
4134
|
}
|
4125
4135
|
const record = { ...data };
|
4126
|
-
const serializable = { xata, ...removeLinksFromObject(data) };
|
4127
4136
|
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
4128
4137
|
record.read = function(columns2) {
|
4129
4138
|
return db[table].read(record["id"], columns2);
|
4130
4139
|
};
|
4131
4140
|
record.update = function(data2, b, c) {
|
4132
|
-
const columns2 =
|
4141
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
4133
4142
|
const ifVersion = parseIfVersion(b, c);
|
4134
4143
|
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
4135
4144
|
};
|
4136
4145
|
record.replace = function(data2, b, c) {
|
4137
|
-
const columns2 =
|
4146
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
4138
4147
|
const ifVersion = parseIfVersion(b, c);
|
4139
4148
|
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
4140
4149
|
};
|
4141
4150
|
record.delete = function() {
|
4142
4151
|
return db[table].delete(record["id"]);
|
4143
4152
|
};
|
4144
|
-
|
4153
|
+
if (metadata !== void 0) {
|
4154
|
+
record.xata = Object.freeze(metadata);
|
4155
|
+
}
|
4145
4156
|
record.getMetadata = function() {
|
4146
4157
|
return record.xata;
|
4147
4158
|
};
|
4148
4159
|
record.toSerializable = function() {
|
4149
|
-
return JSON.parse(JSON.stringify(
|
4160
|
+
return JSON.parse(JSON.stringify(record));
|
4150
4161
|
};
|
4151
4162
|
record.toString = function() {
|
4152
|
-
return JSON.stringify(
|
4163
|
+
return JSON.stringify(record);
|
4153
4164
|
};
|
4154
4165
|
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
4155
4166
|
Object.defineProperty(record, prop, { enumerable: false });
|
@@ -4167,7 +4178,7 @@ function extractId(value) {
|
|
4167
4178
|
function isValidColumn(columns, column) {
|
4168
4179
|
if (columns.includes("*"))
|
4169
4180
|
return true;
|
4170
|
-
return columns.filter((item) => item.startsWith(column.name)).length > 0;
|
4181
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
4171
4182
|
}
|
4172
4183
|
function parseIfVersion(...args) {
|
4173
4184
|
for (const arg of args) {
|
@@ -4178,12 +4189,6 @@ function parseIfVersion(...args) {
|
|
4178
4189
|
return void 0;
|
4179
4190
|
}
|
4180
4191
|
|
4181
|
-
var __defProp$3 = Object.defineProperty;
|
4182
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4183
|
-
var __publicField$3 = (obj, key, value) => {
|
4184
|
-
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4185
|
-
return value;
|
4186
|
-
};
|
4187
4192
|
var __accessCheck$3 = (obj, member, msg) => {
|
4188
4193
|
if (!member.has(obj))
|
4189
4194
|
throw TypeError("Cannot " + msg);
|
@@ -4206,8 +4211,6 @@ var _map;
|
|
4206
4211
|
class SimpleCache {
|
4207
4212
|
constructor(options = {}) {
|
4208
4213
|
__privateAdd$3(this, _map, void 0);
|
4209
|
-
__publicField$3(this, "capacity");
|
4210
|
-
__publicField$3(this, "defaultQueryTTL");
|
4211
4214
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
4212
4215
|
this.capacity = options.max ?? 500;
|
4213
4216
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
@@ -4252,10 +4255,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
4252
4255
|
const startsWith = (value) => ({ $startsWith: value });
|
4253
4256
|
const endsWith = (value) => ({ $endsWith: value });
|
4254
4257
|
const pattern = (value) => ({ $pattern: value });
|
4258
|
+
const iPattern = (value) => ({ $iPattern: value });
|
4255
4259
|
const is = (value) => ({ $is: value });
|
4256
4260
|
const equals = is;
|
4257
4261
|
const isNot = (value) => ({ $isNot: value });
|
4258
4262
|
const contains = (value) => ({ $contains: value });
|
4263
|
+
const iContains = (value) => ({ $iContains: value });
|
4259
4264
|
const includes = (value) => ({ $includes: value });
|
4260
4265
|
const includesAll = (value) => ({ $includesAll: value });
|
4261
4266
|
const includesNone = (value) => ({ $includesNone: value });
|
@@ -4311,6 +4316,80 @@ class SchemaPlugin extends XataPlugin {
|
|
4311
4316
|
_tables = new WeakMap();
|
4312
4317
|
_schemaTables$1 = new WeakMap();
|
4313
4318
|
|
4319
|
+
class FilesPlugin extends XataPlugin {
|
4320
|
+
build(pluginOptions) {
|
4321
|
+
return {
|
4322
|
+
download: async (location) => {
|
4323
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4324
|
+
return await getFileItem({
|
4325
|
+
pathParams: {
|
4326
|
+
workspace: "{workspaceId}",
|
4327
|
+
dbBranchName: "{dbBranch}",
|
4328
|
+
region: "{region}",
|
4329
|
+
tableName: table ?? "",
|
4330
|
+
recordId: record ?? "",
|
4331
|
+
columnName: column ?? "",
|
4332
|
+
fileId
|
4333
|
+
},
|
4334
|
+
...pluginOptions,
|
4335
|
+
rawResponse: true
|
4336
|
+
});
|
4337
|
+
},
|
4338
|
+
upload: async (location, file, options) => {
|
4339
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4340
|
+
const resolvedFile = await file;
|
4341
|
+
const contentType = options?.mediaType || getContentType(resolvedFile);
|
4342
|
+
const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
|
4343
|
+
return await putFileItem({
|
4344
|
+
...pluginOptions,
|
4345
|
+
pathParams: {
|
4346
|
+
workspace: "{workspaceId}",
|
4347
|
+
dbBranchName: "{dbBranch}",
|
4348
|
+
region: "{region}",
|
4349
|
+
tableName: table ?? "",
|
4350
|
+
recordId: record ?? "",
|
4351
|
+
columnName: column ?? "",
|
4352
|
+
fileId
|
4353
|
+
},
|
4354
|
+
body,
|
4355
|
+
headers: { "Content-Type": contentType }
|
4356
|
+
});
|
4357
|
+
},
|
4358
|
+
delete: async (location) => {
|
4359
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4360
|
+
return await deleteFileItem({
|
4361
|
+
pathParams: {
|
4362
|
+
workspace: "{workspaceId}",
|
4363
|
+
dbBranchName: "{dbBranch}",
|
4364
|
+
region: "{region}",
|
4365
|
+
tableName: table ?? "",
|
4366
|
+
recordId: record ?? "",
|
4367
|
+
columnName: column ?? "",
|
4368
|
+
fileId
|
4369
|
+
},
|
4370
|
+
...pluginOptions
|
4371
|
+
});
|
4372
|
+
}
|
4373
|
+
};
|
4374
|
+
}
|
4375
|
+
}
|
4376
|
+
function getContentType(file) {
|
4377
|
+
if (typeof file === "string") {
|
4378
|
+
return "text/plain";
|
4379
|
+
}
|
4380
|
+
if ("mediaType" in file) {
|
4381
|
+
return file.mediaType;
|
4382
|
+
}
|
4383
|
+
if (isBlob(file)) {
|
4384
|
+
return file.type;
|
4385
|
+
}
|
4386
|
+
try {
|
4387
|
+
return file.type;
|
4388
|
+
} catch (e) {
|
4389
|
+
}
|
4390
|
+
return "application/octet-stream";
|
4391
|
+
}
|
4392
|
+
|
4314
4393
|
var __accessCheck$1 = (obj, member, msg) => {
|
4315
4394
|
if (!member.has(obj))
|
4316
4395
|
throw TypeError("Cannot " + msg);
|
@@ -4346,22 +4425,26 @@ class SearchPlugin extends XataPlugin {
|
|
4346
4425
|
build(pluginOptions) {
|
4347
4426
|
return {
|
4348
4427
|
all: async (query, options = {}) => {
|
4349
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4428
|
+
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4350
4429
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4351
|
-
return
|
4352
|
-
|
4353
|
-
|
4354
|
-
|
4430
|
+
return {
|
4431
|
+
totalCount,
|
4432
|
+
records: records.map((record) => {
|
4433
|
+
const { table = "orphan" } = record.xata;
|
4434
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
4435
|
+
})
|
4436
|
+
};
|
4355
4437
|
},
|
4356
4438
|
byTable: async (query, options = {}) => {
|
4357
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4439
|
+
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4358
4440
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4359
|
-
|
4441
|
+
const records = rawRecords.reduce((acc, record) => {
|
4360
4442
|
const { table = "orphan" } = record.xata;
|
4361
4443
|
const items = acc[table] ?? [];
|
4362
4444
|
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
4363
4445
|
return { ...acc, [table]: [...items, item] };
|
4364
4446
|
}, {});
|
4447
|
+
return { totalCount, records };
|
4365
4448
|
}
|
4366
4449
|
};
|
4367
4450
|
}
|
@@ -4370,13 +4453,13 @@ _schemaTables = new WeakMap();
|
|
4370
4453
|
_search = new WeakSet();
|
4371
4454
|
search_fn = async function(query, options, pluginOptions) {
|
4372
4455
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
4373
|
-
const { records } = await searchBranch({
|
4456
|
+
const { records, totalCount } = await searchBranch({
|
4374
4457
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4375
4458
|
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
4376
4459
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
4377
4460
|
...pluginOptions
|
4378
4461
|
});
|
4379
|
-
return records;
|
4462
|
+
return { records, totalCount };
|
4380
4463
|
};
|
4381
4464
|
_getSchemaTables = new WeakSet();
|
4382
4465
|
getSchemaTables_fn = async function(pluginOptions) {
|
@@ -4477,12 +4560,6 @@ class TransactionPlugin extends XataPlugin {
|
|
4477
4560
|
}
|
4478
4561
|
}
|
4479
4562
|
|
4480
|
-
var __defProp$2 = Object.defineProperty;
|
4481
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4482
|
-
var __publicField$2 = (obj, key, value) => {
|
4483
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4484
|
-
return value;
|
4485
|
-
};
|
4486
4563
|
var __accessCheck = (obj, member, msg) => {
|
4487
4564
|
if (!member.has(obj))
|
4488
4565
|
throw TypeError("Cannot " + msg);
|
@@ -4512,11 +4589,6 @@ const buildClient = (plugins) => {
|
|
4512
4589
|
__privateAdd(this, _parseOptions);
|
4513
4590
|
__privateAdd(this, _getFetchProps);
|
4514
4591
|
__privateAdd(this, _options, void 0);
|
4515
|
-
__publicField$2(this, "db");
|
4516
|
-
__publicField$2(this, "search");
|
4517
|
-
__publicField$2(this, "transactions");
|
4518
|
-
__publicField$2(this, "sql");
|
4519
|
-
__publicField$2(this, "files");
|
4520
4592
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
4521
4593
|
__privateSet(this, _options, safeOptions);
|
4522
4594
|
const pluginOptions = {
|
@@ -4630,17 +4702,11 @@ const buildClient = (plugins) => {
|
|
4630
4702
|
class BaseClient extends buildClient() {
|
4631
4703
|
}
|
4632
4704
|
|
4633
|
-
var __defProp$1 = Object.defineProperty;
|
4634
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4635
|
-
var __publicField$1 = (obj, key, value) => {
|
4636
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4637
|
-
return value;
|
4638
|
-
};
|
4639
4705
|
const META = "__";
|
4640
4706
|
const VALUE = "___";
|
4641
4707
|
class Serializer {
|
4642
4708
|
constructor() {
|
4643
|
-
|
4709
|
+
this.classes = {};
|
4644
4710
|
}
|
4645
4711
|
add(clazz) {
|
4646
4712
|
this.classes[clazz.name] = clazz;
|
@@ -4703,31 +4769,9 @@ const deserialize = (json) => {
|
|
4703
4769
|
return defaultSerializer.fromJSON(json);
|
4704
4770
|
};
|
4705
4771
|
|
4706
|
-
function buildWorkerRunner(config) {
|
4707
|
-
return function xataWorker(name, worker) {
|
4708
|
-
return async (...args) => {
|
4709
|
-
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
4710
|
-
const result = await fetch(url, {
|
4711
|
-
method: "POST",
|
4712
|
-
headers: { "Content-Type": "application/json" },
|
4713
|
-
body: serialize({ args })
|
4714
|
-
});
|
4715
|
-
const text = await result.text();
|
4716
|
-
return deserialize(text);
|
4717
|
-
};
|
4718
|
-
};
|
4719
|
-
}
|
4720
|
-
|
4721
|
-
var __defProp = Object.defineProperty;
|
4722
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4723
|
-
var __publicField = (obj, key, value) => {
|
4724
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4725
|
-
return value;
|
4726
|
-
};
|
4727
4772
|
class XataError extends Error {
|
4728
4773
|
constructor(message, status) {
|
4729
4774
|
super(message);
|
4730
|
-
__publicField(this, "status");
|
4731
4775
|
this.status = status;
|
4732
4776
|
}
|
4733
4777
|
}
|
@@ -4751,6 +4795,7 @@ exports.SchemaPlugin = SchemaPlugin;
|
|
4751
4795
|
exports.SearchPlugin = SearchPlugin;
|
4752
4796
|
exports.Serializer = Serializer;
|
4753
4797
|
exports.SimpleCache = SimpleCache;
|
4798
|
+
exports.TransactionPlugin = TransactionPlugin;
|
4754
4799
|
exports.XataApiClient = XataApiClient;
|
4755
4800
|
exports.XataApiPlugin = XataApiPlugin;
|
4756
4801
|
exports.XataError = XataError;
|
@@ -4761,13 +4806,13 @@ exports.addGitBranchesEntry = addGitBranchesEntry;
|
|
4761
4806
|
exports.addTableColumn = addTableColumn;
|
4762
4807
|
exports.aggregateTable = aggregateTable;
|
4763
4808
|
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
4809
|
+
exports.applyMigration = applyMigration;
|
4764
4810
|
exports.askTable = askTable;
|
4765
4811
|
exports.askTableSession = askTableSession;
|
4766
4812
|
exports.branchTransaction = branchTransaction;
|
4767
4813
|
exports.buildClient = buildClient;
|
4768
4814
|
exports.buildPreviewBranchName = buildPreviewBranchName;
|
4769
4815
|
exports.buildProviderString = buildProviderString;
|
4770
|
-
exports.buildWorkerRunner = buildWorkerRunner;
|
4771
4816
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
4772
4817
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
4773
4818
|
exports.compareBranchSchemas = compareBranchSchemas;
|
@@ -4776,6 +4821,7 @@ exports.compareMigrationRequest = compareMigrationRequest;
|
|
4776
4821
|
exports.contains = contains;
|
4777
4822
|
exports.copyBranch = copyBranch;
|
4778
4823
|
exports.createBranch = createBranch;
|
4824
|
+
exports.createCluster = createCluster;
|
4779
4825
|
exports.createDatabase = createDatabase;
|
4780
4826
|
exports.createMigrationRequest = createMigrationRequest;
|
4781
4827
|
exports.createTable = createTable;
|
@@ -4792,6 +4838,7 @@ exports.deleteRecord = deleteRecord;
|
|
4792
4838
|
exports.deleteTable = deleteTable;
|
4793
4839
|
exports.deleteUser = deleteUser;
|
4794
4840
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
4841
|
+
exports.deleteUserOAuthClient = deleteUserOAuthClient;
|
4795
4842
|
exports.deleteWorkspace = deleteWorkspace;
|
4796
4843
|
exports.deserialize = deserialize;
|
4797
4844
|
exports.endsWith = endsWith;
|
@@ -4810,6 +4857,7 @@ exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
|
4810
4857
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
4811
4858
|
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
4812
4859
|
exports.getBranchStats = getBranchStats;
|
4860
|
+
exports.getCluster = getCluster;
|
4813
4861
|
exports.getColumn = getColumn;
|
4814
4862
|
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
4815
4863
|
exports.getDatabaseList = getDatabaseList;
|
@@ -4823,6 +4871,7 @@ exports.getMigrationRequest = getMigrationRequest;
|
|
4823
4871
|
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
4824
4872
|
exports.getPreviewBranch = getPreviewBranch;
|
4825
4873
|
exports.getRecord = getRecord;
|
4874
|
+
exports.getSchema = getSchema;
|
4826
4875
|
exports.getTableColumns = getTableColumns;
|
4827
4876
|
exports.getTableSchema = getTableSchema;
|
4828
4877
|
exports.getUser = getUser;
|
@@ -4838,6 +4887,8 @@ exports.greaterThan = greaterThan;
|
|
4838
4887
|
exports.greaterThanEquals = greaterThanEquals;
|
4839
4888
|
exports.gt = gt;
|
4840
4889
|
exports.gte = gte;
|
4890
|
+
exports.iContains = iContains;
|
4891
|
+
exports.iPattern = iPattern;
|
4841
4892
|
exports.includes = includes;
|
4842
4893
|
exports.includesAll = includesAll;
|
4843
4894
|
exports.includesAny = includesAny;
|
@@ -4851,11 +4902,14 @@ exports.isHostProviderAlias = isHostProviderAlias;
|
|
4851
4902
|
exports.isHostProviderBuilder = isHostProviderBuilder;
|
4852
4903
|
exports.isIdentifiable = isIdentifiable;
|
4853
4904
|
exports.isNot = isNot;
|
4905
|
+
exports.isValidExpandedColumn = isValidExpandedColumn;
|
4906
|
+
exports.isValidSelectableColumns = isValidSelectableColumns;
|
4854
4907
|
exports.isXataRecord = isXataRecord;
|
4855
4908
|
exports.le = le;
|
4856
4909
|
exports.lessEquals = lessEquals;
|
4857
4910
|
exports.lessThan = lessThan;
|
4858
4911
|
exports.lessThanEquals = lessThanEquals;
|
4912
|
+
exports.listClusters = listClusters;
|
4859
4913
|
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
4860
4914
|
exports.listRegions = listRegions;
|
4861
4915
|
exports.lt = lt;
|
@@ -4866,6 +4920,7 @@ exports.operationsByTag = operationsByTag;
|
|
4866
4920
|
exports.parseProviderString = parseProviderString;
|
4867
4921
|
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
4868
4922
|
exports.pattern = pattern;
|
4923
|
+
exports.pgRollStatus = pgRollStatus;
|
4869
4924
|
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
4870
4925
|
exports.pushBranchMigrations = pushBranchMigrations;
|
4871
4926
|
exports.putFile = putFile;
|
@@ -4887,6 +4942,7 @@ exports.summarizeTable = summarizeTable;
|
|
4887
4942
|
exports.transformImage = transformImage;
|
4888
4943
|
exports.updateBranchMetadata = updateBranchMetadata;
|
4889
4944
|
exports.updateBranchSchema = updateBranchSchema;
|
4945
|
+
exports.updateCluster = updateCluster;
|
4890
4946
|
exports.updateColumn = updateColumn;
|
4891
4947
|
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
4892
4948
|
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|