@xata.io/client 0.0.0-alpha.vf2894b5 → 0.0.0-alpha.vf2950db06c33bba882032c181cc784c0501526f1
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 +61 -1
- package/dist/index.cjs +247 -171
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2967 -2669
- package/dist/index.mjs +239 -171
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -528,7 +528,7 @@ function defaultOnOpen(response) {
|
|
528
528
|
}
|
529
529
|
}
|
530
530
|
|
531
|
-
const VERSION = "0.
|
531
|
+
const VERSION = "0.28.3";
|
532
532
|
|
533
533
|
class ErrorWithCause extends Error {
|
534
534
|
constructor(message, options) {
|
@@ -571,6 +571,67 @@ function getMessage(data) {
|
|
571
571
|
}
|
572
572
|
}
|
573
573
|
|
574
|
+
function getHostUrl(provider, type) {
|
575
|
+
if (isHostProviderAlias(provider)) {
|
576
|
+
return providers[provider][type];
|
577
|
+
} else if (isHostProviderBuilder(provider)) {
|
578
|
+
return provider[type];
|
579
|
+
}
|
580
|
+
throw new Error("Invalid API provider");
|
581
|
+
}
|
582
|
+
const providers = {
|
583
|
+
production: {
|
584
|
+
main: "https://api.xata.io",
|
585
|
+
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
586
|
+
},
|
587
|
+
staging: {
|
588
|
+
main: "https://api.staging-xata.dev",
|
589
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
590
|
+
},
|
591
|
+
dev: {
|
592
|
+
main: "https://api.dev-xata.dev",
|
593
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
594
|
+
},
|
595
|
+
local: {
|
596
|
+
main: "http://localhost:6001",
|
597
|
+
workspaces: "http://{workspaceId}.{region}.localhost:6001"
|
598
|
+
}
|
599
|
+
};
|
600
|
+
function isHostProviderAlias(alias) {
|
601
|
+
return isString(alias) && Object.keys(providers).includes(alias);
|
602
|
+
}
|
603
|
+
function isHostProviderBuilder(builder) {
|
604
|
+
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
605
|
+
}
|
606
|
+
function parseProviderString(provider = "production") {
|
607
|
+
if (isHostProviderAlias(provider)) {
|
608
|
+
return provider;
|
609
|
+
}
|
610
|
+
const [main, workspaces] = provider.split(",");
|
611
|
+
if (!main || !workspaces)
|
612
|
+
return null;
|
613
|
+
return { main, workspaces };
|
614
|
+
}
|
615
|
+
function buildProviderString(provider) {
|
616
|
+
if (isHostProviderAlias(provider))
|
617
|
+
return provider;
|
618
|
+
return `${provider.main},${provider.workspaces}`;
|
619
|
+
}
|
620
|
+
function parseWorkspacesUrlParts(url) {
|
621
|
+
if (!isString(url))
|
622
|
+
return null;
|
623
|
+
const matches = {
|
624
|
+
production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/),
|
625
|
+
staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
|
626
|
+
dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/),
|
627
|
+
local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(\d+)/)
|
628
|
+
};
|
629
|
+
const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
|
630
|
+
if (!isHostProviderAlias(host) || !match)
|
631
|
+
return null;
|
632
|
+
return { workspace: match[1], region: match[2], host };
|
633
|
+
}
|
634
|
+
|
574
635
|
const pool = new ApiRequestPool();
|
575
636
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
576
637
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
@@ -586,6 +647,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
586
647
|
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
587
648
|
};
|
588
649
|
function buildBaseUrl({
|
650
|
+
method,
|
589
651
|
endpoint,
|
590
652
|
path,
|
591
653
|
workspacesApiUrl,
|
@@ -593,7 +655,24 @@ function buildBaseUrl({
|
|
593
655
|
pathParams = {}
|
594
656
|
}) {
|
595
657
|
if (endpoint === "dataPlane") {
|
596
|
-
|
658
|
+
let url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
659
|
+
if (method.toUpperCase() === "PUT" && [
|
660
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
661
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}"
|
662
|
+
].includes(path)) {
|
663
|
+
const { host } = parseWorkspacesUrlParts(url) ?? {};
|
664
|
+
switch (host) {
|
665
|
+
case "production":
|
666
|
+
url = url.replace("xata.sh", "upload.xata.sh");
|
667
|
+
break;
|
668
|
+
case "staging":
|
669
|
+
url = url.replace("staging-xata.dev", "upload.staging-xata.dev");
|
670
|
+
break;
|
671
|
+
case "dev":
|
672
|
+
url = url.replace("dev-xata.dev", "upload.dev-xata.dev");
|
673
|
+
break;
|
674
|
+
}
|
675
|
+
}
|
597
676
|
const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
|
598
677
|
return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
|
599
678
|
}
|
@@ -642,9 +721,9 @@ async function fetch$1({
|
|
642
721
|
return await trace(
|
643
722
|
`${method.toUpperCase()} ${path}`,
|
644
723
|
async ({ setAttributes }) => {
|
645
|
-
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
724
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
646
725
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
647
|
-
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
726
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\.[^.]+\./, "http://") : fullUrl;
|
648
727
|
setAttributes({
|
649
728
|
[TraceAttributes.HTTP_URL]: url,
|
650
729
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
@@ -725,7 +804,7 @@ function fetchSSERequest({
|
|
725
804
|
clientName,
|
726
805
|
xataAgentExtra
|
727
806
|
}) {
|
728
|
-
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
807
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
729
808
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
730
809
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
731
810
|
void fetchEventSource(url, {
|
@@ -768,6 +847,20 @@ function parseUrl(url) {
|
|
768
847
|
|
769
848
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
770
849
|
|
850
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/apply", method: "post", ...variables, signal });
|
851
|
+
const pgRollStatus = (variables, signal) => dataPlaneFetch({
|
852
|
+
url: "/db/{dbBranchName}/pgroll/status",
|
853
|
+
method: "get",
|
854
|
+
...variables,
|
855
|
+
signal
|
856
|
+
});
|
857
|
+
const pgRollJobStatus = (variables, signal) => dataPlaneFetch({
|
858
|
+
url: "/db/{dbBranchName}/pgroll/jobs/{jobId}",
|
859
|
+
method: "get",
|
860
|
+
...variables,
|
861
|
+
signal
|
862
|
+
});
|
863
|
+
const pgRollMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/migrations", method: "get", ...variables, signal });
|
771
864
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
772
865
|
url: "/dbs/{dbName}",
|
773
866
|
method: "get",
|
@@ -787,6 +880,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
787
880
|
...variables,
|
788
881
|
signal
|
789
882
|
});
|
883
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
884
|
+
url: "/db/{dbBranchName}/schema",
|
885
|
+
method: "get",
|
886
|
+
...variables,
|
887
|
+
signal
|
888
|
+
});
|
790
889
|
const copyBranch = (variables, signal) => dataPlaneFetch({
|
791
890
|
url: "/db/{dbBranchName}/copy",
|
792
891
|
method: "post",
|
@@ -968,6 +1067,12 @@ const fileAccess = (variables, signal) => dataPlaneFetch({
|
|
968
1067
|
...variables,
|
969
1068
|
signal
|
970
1069
|
});
|
1070
|
+
const fileUpload = (variables, signal) => dataPlaneFetch({
|
1071
|
+
url: "/file/{fileId}",
|
1072
|
+
method: "put",
|
1073
|
+
...variables,
|
1074
|
+
signal
|
1075
|
+
});
|
971
1076
|
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
972
1077
|
url: "/db/{dbBranchName}/sql",
|
973
1078
|
method: "post",
|
@@ -976,6 +1081,10 @@ const sqlQuery = (variables, signal) => dataPlaneFetch({
|
|
976
1081
|
});
|
977
1082
|
const operationsByTag$2 = {
|
978
1083
|
branch: {
|
1084
|
+
applyMigration,
|
1085
|
+
pgRollStatus,
|
1086
|
+
pgRollJobStatus,
|
1087
|
+
pgRollMigrationHistory,
|
979
1088
|
getBranchList,
|
980
1089
|
getBranchDetails,
|
981
1090
|
createBranch,
|
@@ -990,6 +1099,7 @@ const operationsByTag$2 = {
|
|
990
1099
|
resolveBranch
|
991
1100
|
},
|
992
1101
|
migrations: {
|
1102
|
+
getSchema,
|
993
1103
|
getBranchMigrationHistory,
|
994
1104
|
getBranchMigrationPlan,
|
995
1105
|
executeBranchMigrationPlan,
|
@@ -1033,7 +1143,7 @@ const operationsByTag$2 = {
|
|
1033
1143
|
deleteRecord,
|
1034
1144
|
bulkInsertTableRecords
|
1035
1145
|
},
|
1036
|
-
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1146
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
|
1037
1147
|
searchAndFilter: {
|
1038
1148
|
queryTable,
|
1039
1149
|
searchBranch,
|
@@ -1240,61 +1350,6 @@ const operationsByTag$1 = {
|
|
1240
1350
|
|
1241
1351
|
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
1242
1352
|
|
1243
|
-
function getHostUrl(provider, type) {
|
1244
|
-
if (isHostProviderAlias(provider)) {
|
1245
|
-
return providers[provider][type];
|
1246
|
-
} else if (isHostProviderBuilder(provider)) {
|
1247
|
-
return provider[type];
|
1248
|
-
}
|
1249
|
-
throw new Error("Invalid API provider");
|
1250
|
-
}
|
1251
|
-
const providers = {
|
1252
|
-
production: {
|
1253
|
-
main: "https://api.xata.io",
|
1254
|
-
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
1255
|
-
},
|
1256
|
-
staging: {
|
1257
|
-
main: "https://api.staging-xata.dev",
|
1258
|
-
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1259
|
-
},
|
1260
|
-
dev: {
|
1261
|
-
main: "https://api.dev-xata.dev",
|
1262
|
-
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
1263
|
-
}
|
1264
|
-
};
|
1265
|
-
function isHostProviderAlias(alias) {
|
1266
|
-
return isString(alias) && Object.keys(providers).includes(alias);
|
1267
|
-
}
|
1268
|
-
function isHostProviderBuilder(builder) {
|
1269
|
-
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
1270
|
-
}
|
1271
|
-
function parseProviderString(provider = "production") {
|
1272
|
-
if (isHostProviderAlias(provider)) {
|
1273
|
-
return provider;
|
1274
|
-
}
|
1275
|
-
const [main, workspaces] = provider.split(",");
|
1276
|
-
if (!main || !workspaces)
|
1277
|
-
return null;
|
1278
|
-
return { main, workspaces };
|
1279
|
-
}
|
1280
|
-
function buildProviderString(provider) {
|
1281
|
-
if (isHostProviderAlias(provider))
|
1282
|
-
return provider;
|
1283
|
-
return `${provider.main},${provider.workspaces}`;
|
1284
|
-
}
|
1285
|
-
function parseWorkspacesUrlParts(url) {
|
1286
|
-
if (!isString(url))
|
1287
|
-
return null;
|
1288
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1289
|
-
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1290
|
-
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1291
|
-
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1292
|
-
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
1293
|
-
if (!match)
|
1294
|
-
return null;
|
1295
|
-
return { workspace: match[1], region: match[2] };
|
1296
|
-
}
|
1297
|
-
|
1298
1353
|
var __accessCheck$7 = (obj, member, msg) => {
|
1299
1354
|
if (!member.has(obj))
|
1300
1355
|
throw TypeError("Cannot " + msg);
|
@@ -2619,75 +2674,6 @@ class XataApiPlugin {
|
|
2619
2674
|
class XataPlugin {
|
2620
2675
|
}
|
2621
2676
|
|
2622
|
-
class FilesPlugin extends XataPlugin {
|
2623
|
-
build(pluginOptions) {
|
2624
|
-
return {
|
2625
|
-
download: async (location) => {
|
2626
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2627
|
-
return await getFileItem({
|
2628
|
-
pathParams: {
|
2629
|
-
workspace: "{workspaceId}",
|
2630
|
-
dbBranchName: "{dbBranch}",
|
2631
|
-
region: "{region}",
|
2632
|
-
tableName: table ?? "",
|
2633
|
-
recordId: record ?? "",
|
2634
|
-
columnName: column ?? "",
|
2635
|
-
fileId
|
2636
|
-
},
|
2637
|
-
...pluginOptions,
|
2638
|
-
rawResponse: true
|
2639
|
-
});
|
2640
|
-
},
|
2641
|
-
upload: async (location, file) => {
|
2642
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2643
|
-
const contentType = getContentType(file);
|
2644
|
-
return await putFileItem({
|
2645
|
-
...pluginOptions,
|
2646
|
-
pathParams: {
|
2647
|
-
workspace: "{workspaceId}",
|
2648
|
-
dbBranchName: "{dbBranch}",
|
2649
|
-
region: "{region}",
|
2650
|
-
tableName: table ?? "",
|
2651
|
-
recordId: record ?? "",
|
2652
|
-
columnName: column ?? "",
|
2653
|
-
fileId
|
2654
|
-
},
|
2655
|
-
body: file,
|
2656
|
-
headers: { "Content-Type": contentType }
|
2657
|
-
});
|
2658
|
-
},
|
2659
|
-
delete: async (location) => {
|
2660
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2661
|
-
return await deleteFileItem({
|
2662
|
-
pathParams: {
|
2663
|
-
workspace: "{workspaceId}",
|
2664
|
-
dbBranchName: "{dbBranch}",
|
2665
|
-
region: "{region}",
|
2666
|
-
tableName: table ?? "",
|
2667
|
-
recordId: record ?? "",
|
2668
|
-
columnName: column ?? "",
|
2669
|
-
fileId
|
2670
|
-
},
|
2671
|
-
...pluginOptions
|
2672
|
-
});
|
2673
|
-
}
|
2674
|
-
};
|
2675
|
-
}
|
2676
|
-
}
|
2677
|
-
function getContentType(file) {
|
2678
|
-
if (typeof file === "string") {
|
2679
|
-
return "text/plain";
|
2680
|
-
}
|
2681
|
-
if (isBlob(file)) {
|
2682
|
-
return file.type;
|
2683
|
-
}
|
2684
|
-
try {
|
2685
|
-
return file.type;
|
2686
|
-
} catch (e) {
|
2687
|
-
}
|
2688
|
-
return "application/octet-stream";
|
2689
|
-
}
|
2690
|
-
|
2691
2677
|
function buildTransformString(transformations) {
|
2692
2678
|
return transformations.flatMap(
|
2693
2679
|
(t) => Object.entries(t).map(([key, value]) => {
|
@@ -2719,16 +2705,18 @@ function transformImage(url, ...transformations) {
|
|
2719
2705
|
class XataFile {
|
2720
2706
|
constructor(file) {
|
2721
2707
|
this.id = file.id;
|
2722
|
-
this.name = file.name
|
2723
|
-
this.mediaType = file.mediaType
|
2708
|
+
this.name = file.name;
|
2709
|
+
this.mediaType = file.mediaType;
|
2724
2710
|
this.base64Content = file.base64Content;
|
2725
|
-
this.enablePublicUrl = file.enablePublicUrl
|
2726
|
-
this.signedUrlTimeout = file.signedUrlTimeout
|
2727
|
-
this.
|
2728
|
-
this.
|
2729
|
-
this.
|
2711
|
+
this.enablePublicUrl = file.enablePublicUrl;
|
2712
|
+
this.signedUrlTimeout = file.signedUrlTimeout;
|
2713
|
+
this.uploadUrlTimeout = file.uploadUrlTimeout;
|
2714
|
+
this.size = file.size;
|
2715
|
+
this.version = file.version;
|
2716
|
+
this.url = file.url;
|
2730
2717
|
this.signedUrl = file.signedUrl;
|
2731
|
-
this.
|
2718
|
+
this.uploadUrl = file.uploadUrl;
|
2719
|
+
this.attributes = file.attributes;
|
2732
2720
|
}
|
2733
2721
|
static fromBuffer(buffer, options = {}) {
|
2734
2722
|
const base64Content = buffer.toString("base64");
|
@@ -2818,7 +2806,7 @@ class XataFile {
|
|
2818
2806
|
const parseInputFileEntry = async (entry) => {
|
2819
2807
|
if (!isDefined(entry))
|
2820
2808
|
return null;
|
2821
|
-
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2809
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
|
2822
2810
|
return compactObject({
|
2823
2811
|
id,
|
2824
2812
|
// Name cannot be an empty string in our API
|
@@ -2826,7 +2814,8 @@ const parseInputFileEntry = async (entry) => {
|
|
2826
2814
|
mediaType,
|
2827
2815
|
base64Content,
|
2828
2816
|
enablePublicUrl,
|
2829
|
-
signedUrlTimeout
|
2817
|
+
signedUrlTimeout,
|
2818
|
+
uploadUrlTimeout
|
2830
2819
|
});
|
2831
2820
|
};
|
2832
2821
|
|
@@ -3697,7 +3686,7 @@ class RestRepository extends Query {
|
|
3697
3686
|
}
|
3698
3687
|
async search(query, options = {}) {
|
3699
3688
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
3700
|
-
const { records } = await searchTable({
|
3689
|
+
const { records, totalCount } = await searchTable({
|
3701
3690
|
pathParams: {
|
3702
3691
|
workspace: "{workspaceId}",
|
3703
3692
|
dbBranchName: "{dbBranch}",
|
@@ -3717,12 +3706,15 @@ class RestRepository extends Query {
|
|
3717
3706
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3718
3707
|
});
|
3719
3708
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3720
|
-
return
|
3709
|
+
return {
|
3710
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3711
|
+
totalCount
|
3712
|
+
};
|
3721
3713
|
});
|
3722
3714
|
}
|
3723
3715
|
async vectorSearch(column, query, options) {
|
3724
3716
|
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3725
|
-
const { records } = await vectorSearchTable({
|
3717
|
+
const { records, totalCount } = await vectorSearchTable({
|
3726
3718
|
pathParams: {
|
3727
3719
|
workspace: "{workspaceId}",
|
3728
3720
|
dbBranchName: "{dbBranch}",
|
@@ -3739,7 +3731,10 @@ class RestRepository extends Query {
|
|
3739
3731
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3740
3732
|
});
|
3741
3733
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3742
|
-
return
|
3734
|
+
return {
|
3735
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3736
|
+
totalCount
|
3737
|
+
};
|
3743
3738
|
});
|
3744
3739
|
}
|
3745
3740
|
async aggregate(aggs, filter) {
|
@@ -3815,7 +3810,13 @@ class RestRepository extends Query {
|
|
3815
3810
|
},
|
3816
3811
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3817
3812
|
});
|
3818
|
-
|
3813
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3814
|
+
return {
|
3815
|
+
...result,
|
3816
|
+
summaries: result.summaries.map(
|
3817
|
+
(summary) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), summary, data.columns ?? [])
|
3818
|
+
)
|
3819
|
+
};
|
3819
3820
|
});
|
3820
3821
|
}
|
3821
3822
|
ask(question, options) {
|
@@ -4186,7 +4187,9 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4186
4187
|
record.delete = function() {
|
4187
4188
|
return db[table].delete(record["id"]);
|
4188
4189
|
};
|
4189
|
-
|
4190
|
+
if (metadata !== void 0) {
|
4191
|
+
record.xata = Object.freeze(metadata);
|
4192
|
+
}
|
4190
4193
|
record.getMetadata = function() {
|
4191
4194
|
return record.xata;
|
4192
4195
|
};
|
@@ -4289,10 +4292,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
4289
4292
|
const startsWith = (value) => ({ $startsWith: value });
|
4290
4293
|
const endsWith = (value) => ({ $endsWith: value });
|
4291
4294
|
const pattern = (value) => ({ $pattern: value });
|
4295
|
+
const iPattern = (value) => ({ $iPattern: value });
|
4292
4296
|
const is = (value) => ({ $is: value });
|
4293
4297
|
const equals = is;
|
4294
4298
|
const isNot = (value) => ({ $isNot: value });
|
4295
4299
|
const contains = (value) => ({ $contains: value });
|
4300
|
+
const iContains = (value) => ({ $iContains: value });
|
4296
4301
|
const includes = (value) => ({ $includes: value });
|
4297
4302
|
const includesAll = (value) => ({ $includesAll: value });
|
4298
4303
|
const includesNone = (value) => ({ $includesNone: value });
|
@@ -4348,6 +4353,80 @@ class SchemaPlugin extends XataPlugin {
|
|
4348
4353
|
_tables = new WeakMap();
|
4349
4354
|
_schemaTables$1 = new WeakMap();
|
4350
4355
|
|
4356
|
+
class FilesPlugin extends XataPlugin {
|
4357
|
+
build(pluginOptions) {
|
4358
|
+
return {
|
4359
|
+
download: async (location) => {
|
4360
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4361
|
+
return await getFileItem({
|
4362
|
+
pathParams: {
|
4363
|
+
workspace: "{workspaceId}",
|
4364
|
+
dbBranchName: "{dbBranch}",
|
4365
|
+
region: "{region}",
|
4366
|
+
tableName: table ?? "",
|
4367
|
+
recordId: record ?? "",
|
4368
|
+
columnName: column ?? "",
|
4369
|
+
fileId
|
4370
|
+
},
|
4371
|
+
...pluginOptions,
|
4372
|
+
rawResponse: true
|
4373
|
+
});
|
4374
|
+
},
|
4375
|
+
upload: async (location, file, options) => {
|
4376
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4377
|
+
const resolvedFile = await file;
|
4378
|
+
const contentType = options?.mediaType || getContentType(resolvedFile);
|
4379
|
+
const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
|
4380
|
+
return await putFileItem({
|
4381
|
+
...pluginOptions,
|
4382
|
+
pathParams: {
|
4383
|
+
workspace: "{workspaceId}",
|
4384
|
+
dbBranchName: "{dbBranch}",
|
4385
|
+
region: "{region}",
|
4386
|
+
tableName: table ?? "",
|
4387
|
+
recordId: record ?? "",
|
4388
|
+
columnName: column ?? "",
|
4389
|
+
fileId
|
4390
|
+
},
|
4391
|
+
body,
|
4392
|
+
headers: { "Content-Type": contentType }
|
4393
|
+
});
|
4394
|
+
},
|
4395
|
+
delete: async (location) => {
|
4396
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4397
|
+
return await deleteFileItem({
|
4398
|
+
pathParams: {
|
4399
|
+
workspace: "{workspaceId}",
|
4400
|
+
dbBranchName: "{dbBranch}",
|
4401
|
+
region: "{region}",
|
4402
|
+
tableName: table ?? "",
|
4403
|
+
recordId: record ?? "",
|
4404
|
+
columnName: column ?? "",
|
4405
|
+
fileId
|
4406
|
+
},
|
4407
|
+
...pluginOptions
|
4408
|
+
});
|
4409
|
+
}
|
4410
|
+
};
|
4411
|
+
}
|
4412
|
+
}
|
4413
|
+
function getContentType(file) {
|
4414
|
+
if (typeof file === "string") {
|
4415
|
+
return "text/plain";
|
4416
|
+
}
|
4417
|
+
if ("mediaType" in file && file.mediaType !== void 0) {
|
4418
|
+
return file.mediaType;
|
4419
|
+
}
|
4420
|
+
if (isBlob(file)) {
|
4421
|
+
return file.type;
|
4422
|
+
}
|
4423
|
+
try {
|
4424
|
+
return file.type;
|
4425
|
+
} catch (e) {
|
4426
|
+
}
|
4427
|
+
return "application/octet-stream";
|
4428
|
+
}
|
4429
|
+
|
4351
4430
|
var __accessCheck$1 = (obj, member, msg) => {
|
4352
4431
|
if (!member.has(obj))
|
4353
4432
|
throw TypeError("Cannot " + msg);
|
@@ -4383,22 +4462,26 @@ class SearchPlugin extends XataPlugin {
|
|
4383
4462
|
build(pluginOptions) {
|
4384
4463
|
return {
|
4385
4464
|
all: async (query, options = {}) => {
|
4386
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4465
|
+
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4387
4466
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4388
|
-
return
|
4389
|
-
|
4390
|
-
|
4391
|
-
|
4467
|
+
return {
|
4468
|
+
totalCount,
|
4469
|
+
records: records.map((record) => {
|
4470
|
+
const { table = "orphan" } = record.xata;
|
4471
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
4472
|
+
})
|
4473
|
+
};
|
4392
4474
|
},
|
4393
4475
|
byTable: async (query, options = {}) => {
|
4394
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4476
|
+
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4395
4477
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4396
|
-
|
4478
|
+
const records = rawRecords.reduce((acc, record) => {
|
4397
4479
|
const { table = "orphan" } = record.xata;
|
4398
4480
|
const items = acc[table] ?? [];
|
4399
4481
|
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
4400
4482
|
return { ...acc, [table]: [...items, item] };
|
4401
4483
|
}, {});
|
4484
|
+
return { totalCount, records };
|
4402
4485
|
}
|
4403
4486
|
};
|
4404
4487
|
}
|
@@ -4407,13 +4490,13 @@ _schemaTables = new WeakMap();
|
|
4407
4490
|
_search = new WeakSet();
|
4408
4491
|
search_fn = async function(query, options, pluginOptions) {
|
4409
4492
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
4410
|
-
const { records } = await searchBranch({
|
4493
|
+
const { records, totalCount } = await searchBranch({
|
4411
4494
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4412
4495
|
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
4413
4496
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
4414
4497
|
...pluginOptions
|
4415
4498
|
});
|
4416
|
-
return records;
|
4499
|
+
return { records, totalCount };
|
4417
4500
|
};
|
4418
4501
|
_getSchemaTables = new WeakSet();
|
4419
4502
|
getSchemaTables_fn = async function(pluginOptions) {
|
@@ -4723,21 +4806,6 @@ const deserialize = (json) => {
|
|
4723
4806
|
return defaultSerializer.fromJSON(json);
|
4724
4807
|
};
|
4725
4808
|
|
4726
|
-
function buildWorkerRunner(config) {
|
4727
|
-
return function xataWorker(name, worker) {
|
4728
|
-
return async (...args) => {
|
4729
|
-
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
4730
|
-
const result = await fetch(url, {
|
4731
|
-
method: "POST",
|
4732
|
-
headers: { "Content-Type": "application/json" },
|
4733
|
-
body: serialize({ args })
|
4734
|
-
});
|
4735
|
-
const text = await result.text();
|
4736
|
-
return deserialize(text);
|
4737
|
-
};
|
4738
|
-
};
|
4739
|
-
}
|
4740
|
-
|
4741
4809
|
class XataError extends Error {
|
4742
4810
|
constructor(message, status) {
|
4743
4811
|
super(message);
|
@@ -4764,6 +4832,7 @@ exports.SchemaPlugin = SchemaPlugin;
|
|
4764
4832
|
exports.SearchPlugin = SearchPlugin;
|
4765
4833
|
exports.Serializer = Serializer;
|
4766
4834
|
exports.SimpleCache = SimpleCache;
|
4835
|
+
exports.TransactionPlugin = TransactionPlugin;
|
4767
4836
|
exports.XataApiClient = XataApiClient;
|
4768
4837
|
exports.XataApiPlugin = XataApiPlugin;
|
4769
4838
|
exports.XataError = XataError;
|
@@ -4774,13 +4843,13 @@ exports.addGitBranchesEntry = addGitBranchesEntry;
|
|
4774
4843
|
exports.addTableColumn = addTableColumn;
|
4775
4844
|
exports.aggregateTable = aggregateTable;
|
4776
4845
|
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
4846
|
+
exports.applyMigration = applyMigration;
|
4777
4847
|
exports.askTable = askTable;
|
4778
4848
|
exports.askTableSession = askTableSession;
|
4779
4849
|
exports.branchTransaction = branchTransaction;
|
4780
4850
|
exports.buildClient = buildClient;
|
4781
4851
|
exports.buildPreviewBranchName = buildPreviewBranchName;
|
4782
4852
|
exports.buildProviderString = buildProviderString;
|
4783
|
-
exports.buildWorkerRunner = buildWorkerRunner;
|
4784
4853
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
4785
4854
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
4786
4855
|
exports.compareBranchSchemas = compareBranchSchemas;
|
@@ -4814,6 +4883,7 @@ exports.equals = equals;
|
|
4814
4883
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
4815
4884
|
exports.exists = exists;
|
4816
4885
|
exports.fileAccess = fileAccess;
|
4886
|
+
exports.fileUpload = fileUpload;
|
4817
4887
|
exports.ge = ge;
|
4818
4888
|
exports.getAPIKey = getAPIKey;
|
4819
4889
|
exports.getAuthorizationCode = getAuthorizationCode;
|
@@ -4839,6 +4909,7 @@ exports.getMigrationRequest = getMigrationRequest;
|
|
4839
4909
|
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
4840
4910
|
exports.getPreviewBranch = getPreviewBranch;
|
4841
4911
|
exports.getRecord = getRecord;
|
4912
|
+
exports.getSchema = getSchema;
|
4842
4913
|
exports.getTableColumns = getTableColumns;
|
4843
4914
|
exports.getTableSchema = getTableSchema;
|
4844
4915
|
exports.getUser = getUser;
|
@@ -4854,6 +4925,8 @@ exports.greaterThan = greaterThan;
|
|
4854
4925
|
exports.greaterThanEquals = greaterThanEquals;
|
4855
4926
|
exports.gt = gt;
|
4856
4927
|
exports.gte = gte;
|
4928
|
+
exports.iContains = iContains;
|
4929
|
+
exports.iPattern = iPattern;
|
4857
4930
|
exports.includes = includes;
|
4858
4931
|
exports.includesAll = includesAll;
|
4859
4932
|
exports.includesAny = includesAny;
|
@@ -4885,6 +4958,9 @@ exports.operationsByTag = operationsByTag;
|
|
4885
4958
|
exports.parseProviderString = parseProviderString;
|
4886
4959
|
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
4887
4960
|
exports.pattern = pattern;
|
4961
|
+
exports.pgRollJobStatus = pgRollJobStatus;
|
4962
|
+
exports.pgRollMigrationHistory = pgRollMigrationHistory;
|
4963
|
+
exports.pgRollStatus = pgRollStatus;
|
4888
4964
|
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
4889
4965
|
exports.pushBranchMigrations = pushBranchMigrations;
|
4890
4966
|
exports.putFile = putFile;
|