@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.mjs
CHANGED
@@ -526,7 +526,7 @@ function defaultOnOpen(response) {
|
|
526
526
|
}
|
527
527
|
}
|
528
528
|
|
529
|
-
const VERSION = "0.
|
529
|
+
const VERSION = "0.28.3";
|
530
530
|
|
531
531
|
class ErrorWithCause extends Error {
|
532
532
|
constructor(message, options) {
|
@@ -569,6 +569,67 @@ function getMessage(data) {
|
|
569
569
|
}
|
570
570
|
}
|
571
571
|
|
572
|
+
function getHostUrl(provider, type) {
|
573
|
+
if (isHostProviderAlias(provider)) {
|
574
|
+
return providers[provider][type];
|
575
|
+
} else if (isHostProviderBuilder(provider)) {
|
576
|
+
return provider[type];
|
577
|
+
}
|
578
|
+
throw new Error("Invalid API provider");
|
579
|
+
}
|
580
|
+
const providers = {
|
581
|
+
production: {
|
582
|
+
main: "https://api.xata.io",
|
583
|
+
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
584
|
+
},
|
585
|
+
staging: {
|
586
|
+
main: "https://api.staging-xata.dev",
|
587
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
588
|
+
},
|
589
|
+
dev: {
|
590
|
+
main: "https://api.dev-xata.dev",
|
591
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
592
|
+
},
|
593
|
+
local: {
|
594
|
+
main: "http://localhost:6001",
|
595
|
+
workspaces: "http://{workspaceId}.{region}.localhost:6001"
|
596
|
+
}
|
597
|
+
};
|
598
|
+
function isHostProviderAlias(alias) {
|
599
|
+
return isString(alias) && Object.keys(providers).includes(alias);
|
600
|
+
}
|
601
|
+
function isHostProviderBuilder(builder) {
|
602
|
+
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
603
|
+
}
|
604
|
+
function parseProviderString(provider = "production") {
|
605
|
+
if (isHostProviderAlias(provider)) {
|
606
|
+
return provider;
|
607
|
+
}
|
608
|
+
const [main, workspaces] = provider.split(",");
|
609
|
+
if (!main || !workspaces)
|
610
|
+
return null;
|
611
|
+
return { main, workspaces };
|
612
|
+
}
|
613
|
+
function buildProviderString(provider) {
|
614
|
+
if (isHostProviderAlias(provider))
|
615
|
+
return provider;
|
616
|
+
return `${provider.main},${provider.workspaces}`;
|
617
|
+
}
|
618
|
+
function parseWorkspacesUrlParts(url) {
|
619
|
+
if (!isString(url))
|
620
|
+
return null;
|
621
|
+
const matches = {
|
622
|
+
production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/),
|
623
|
+
staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
|
624
|
+
dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/),
|
625
|
+
local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(\d+)/)
|
626
|
+
};
|
627
|
+
const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
|
628
|
+
if (!isHostProviderAlias(host) || !match)
|
629
|
+
return null;
|
630
|
+
return { workspace: match[1], region: match[2], host };
|
631
|
+
}
|
632
|
+
|
572
633
|
const pool = new ApiRequestPool();
|
573
634
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
574
635
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
@@ -584,6 +645,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
584
645
|
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
585
646
|
};
|
586
647
|
function buildBaseUrl({
|
648
|
+
method,
|
587
649
|
endpoint,
|
588
650
|
path,
|
589
651
|
workspacesApiUrl,
|
@@ -591,7 +653,24 @@ function buildBaseUrl({
|
|
591
653
|
pathParams = {}
|
592
654
|
}) {
|
593
655
|
if (endpoint === "dataPlane") {
|
594
|
-
|
656
|
+
let url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
657
|
+
if (method.toUpperCase() === "PUT" && [
|
658
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
659
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}"
|
660
|
+
].includes(path)) {
|
661
|
+
const { host } = parseWorkspacesUrlParts(url) ?? {};
|
662
|
+
switch (host) {
|
663
|
+
case "production":
|
664
|
+
url = url.replace("xata.sh", "upload.xata.sh");
|
665
|
+
break;
|
666
|
+
case "staging":
|
667
|
+
url = url.replace("staging-xata.dev", "upload.staging-xata.dev");
|
668
|
+
break;
|
669
|
+
case "dev":
|
670
|
+
url = url.replace("dev-xata.dev", "upload.dev-xata.dev");
|
671
|
+
break;
|
672
|
+
}
|
673
|
+
}
|
595
674
|
const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
|
596
675
|
return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
|
597
676
|
}
|
@@ -640,9 +719,9 @@ async function fetch$1({
|
|
640
719
|
return await trace(
|
641
720
|
`${method.toUpperCase()} ${path}`,
|
642
721
|
async ({ setAttributes }) => {
|
643
|
-
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
722
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
644
723
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
645
|
-
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
724
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\.[^.]+\./, "http://") : fullUrl;
|
646
725
|
setAttributes({
|
647
726
|
[TraceAttributes.HTTP_URL]: url,
|
648
727
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
@@ -723,7 +802,7 @@ function fetchSSERequest({
|
|
723
802
|
clientName,
|
724
803
|
xataAgentExtra
|
725
804
|
}) {
|
726
|
-
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
805
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
727
806
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
728
807
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
729
808
|
void fetchEventSource(url, {
|
@@ -766,6 +845,20 @@ function parseUrl(url) {
|
|
766
845
|
|
767
846
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
768
847
|
|
848
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/apply", method: "post", ...variables, signal });
|
849
|
+
const pgRollStatus = (variables, signal) => dataPlaneFetch({
|
850
|
+
url: "/db/{dbBranchName}/pgroll/status",
|
851
|
+
method: "get",
|
852
|
+
...variables,
|
853
|
+
signal
|
854
|
+
});
|
855
|
+
const pgRollJobStatus = (variables, signal) => dataPlaneFetch({
|
856
|
+
url: "/db/{dbBranchName}/pgroll/jobs/{jobId}",
|
857
|
+
method: "get",
|
858
|
+
...variables,
|
859
|
+
signal
|
860
|
+
});
|
861
|
+
const pgRollMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/migrations", method: "get", ...variables, signal });
|
769
862
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
770
863
|
url: "/dbs/{dbName}",
|
771
864
|
method: "get",
|
@@ -785,6 +878,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
785
878
|
...variables,
|
786
879
|
signal
|
787
880
|
});
|
881
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
882
|
+
url: "/db/{dbBranchName}/schema",
|
883
|
+
method: "get",
|
884
|
+
...variables,
|
885
|
+
signal
|
886
|
+
});
|
788
887
|
const copyBranch = (variables, signal) => dataPlaneFetch({
|
789
888
|
url: "/db/{dbBranchName}/copy",
|
790
889
|
method: "post",
|
@@ -966,6 +1065,12 @@ const fileAccess = (variables, signal) => dataPlaneFetch({
|
|
966
1065
|
...variables,
|
967
1066
|
signal
|
968
1067
|
});
|
1068
|
+
const fileUpload = (variables, signal) => dataPlaneFetch({
|
1069
|
+
url: "/file/{fileId}",
|
1070
|
+
method: "put",
|
1071
|
+
...variables,
|
1072
|
+
signal
|
1073
|
+
});
|
969
1074
|
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
970
1075
|
url: "/db/{dbBranchName}/sql",
|
971
1076
|
method: "post",
|
@@ -974,6 +1079,10 @@ const sqlQuery = (variables, signal) => dataPlaneFetch({
|
|
974
1079
|
});
|
975
1080
|
const operationsByTag$2 = {
|
976
1081
|
branch: {
|
1082
|
+
applyMigration,
|
1083
|
+
pgRollStatus,
|
1084
|
+
pgRollJobStatus,
|
1085
|
+
pgRollMigrationHistory,
|
977
1086
|
getBranchList,
|
978
1087
|
getBranchDetails,
|
979
1088
|
createBranch,
|
@@ -988,6 +1097,7 @@ const operationsByTag$2 = {
|
|
988
1097
|
resolveBranch
|
989
1098
|
},
|
990
1099
|
migrations: {
|
1100
|
+
getSchema,
|
991
1101
|
getBranchMigrationHistory,
|
992
1102
|
getBranchMigrationPlan,
|
993
1103
|
executeBranchMigrationPlan,
|
@@ -1031,7 +1141,7 @@ const operationsByTag$2 = {
|
|
1031
1141
|
deleteRecord,
|
1032
1142
|
bulkInsertTableRecords
|
1033
1143
|
},
|
1034
|
-
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1144
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
|
1035
1145
|
searchAndFilter: {
|
1036
1146
|
queryTable,
|
1037
1147
|
searchBranch,
|
@@ -1238,61 +1348,6 @@ const operationsByTag$1 = {
|
|
1238
1348
|
|
1239
1349
|
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
1240
1350
|
|
1241
|
-
function getHostUrl(provider, type) {
|
1242
|
-
if (isHostProviderAlias(provider)) {
|
1243
|
-
return providers[provider][type];
|
1244
|
-
} else if (isHostProviderBuilder(provider)) {
|
1245
|
-
return provider[type];
|
1246
|
-
}
|
1247
|
-
throw new Error("Invalid API provider");
|
1248
|
-
}
|
1249
|
-
const providers = {
|
1250
|
-
production: {
|
1251
|
-
main: "https://api.xata.io",
|
1252
|
-
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
1253
|
-
},
|
1254
|
-
staging: {
|
1255
|
-
main: "https://api.staging-xata.dev",
|
1256
|
-
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1257
|
-
},
|
1258
|
-
dev: {
|
1259
|
-
main: "https://api.dev-xata.dev",
|
1260
|
-
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
1261
|
-
}
|
1262
|
-
};
|
1263
|
-
function isHostProviderAlias(alias) {
|
1264
|
-
return isString(alias) && Object.keys(providers).includes(alias);
|
1265
|
-
}
|
1266
|
-
function isHostProviderBuilder(builder) {
|
1267
|
-
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
1268
|
-
}
|
1269
|
-
function parseProviderString(provider = "production") {
|
1270
|
-
if (isHostProviderAlias(provider)) {
|
1271
|
-
return provider;
|
1272
|
-
}
|
1273
|
-
const [main, workspaces] = provider.split(",");
|
1274
|
-
if (!main || !workspaces)
|
1275
|
-
return null;
|
1276
|
-
return { main, workspaces };
|
1277
|
-
}
|
1278
|
-
function buildProviderString(provider) {
|
1279
|
-
if (isHostProviderAlias(provider))
|
1280
|
-
return provider;
|
1281
|
-
return `${provider.main},${provider.workspaces}`;
|
1282
|
-
}
|
1283
|
-
function parseWorkspacesUrlParts(url) {
|
1284
|
-
if (!isString(url))
|
1285
|
-
return null;
|
1286
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1287
|
-
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1288
|
-
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1289
|
-
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1290
|
-
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
1291
|
-
if (!match)
|
1292
|
-
return null;
|
1293
|
-
return { workspace: match[1], region: match[2] };
|
1294
|
-
}
|
1295
|
-
|
1296
1351
|
var __accessCheck$7 = (obj, member, msg) => {
|
1297
1352
|
if (!member.has(obj))
|
1298
1353
|
throw TypeError("Cannot " + msg);
|
@@ -2617,75 +2672,6 @@ class XataApiPlugin {
|
|
2617
2672
|
class XataPlugin {
|
2618
2673
|
}
|
2619
2674
|
|
2620
|
-
class FilesPlugin extends XataPlugin {
|
2621
|
-
build(pluginOptions) {
|
2622
|
-
return {
|
2623
|
-
download: async (location) => {
|
2624
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2625
|
-
return await getFileItem({
|
2626
|
-
pathParams: {
|
2627
|
-
workspace: "{workspaceId}",
|
2628
|
-
dbBranchName: "{dbBranch}",
|
2629
|
-
region: "{region}",
|
2630
|
-
tableName: table ?? "",
|
2631
|
-
recordId: record ?? "",
|
2632
|
-
columnName: column ?? "",
|
2633
|
-
fileId
|
2634
|
-
},
|
2635
|
-
...pluginOptions,
|
2636
|
-
rawResponse: true
|
2637
|
-
});
|
2638
|
-
},
|
2639
|
-
upload: async (location, file) => {
|
2640
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2641
|
-
const contentType = getContentType(file);
|
2642
|
-
return await putFileItem({
|
2643
|
-
...pluginOptions,
|
2644
|
-
pathParams: {
|
2645
|
-
workspace: "{workspaceId}",
|
2646
|
-
dbBranchName: "{dbBranch}",
|
2647
|
-
region: "{region}",
|
2648
|
-
tableName: table ?? "",
|
2649
|
-
recordId: record ?? "",
|
2650
|
-
columnName: column ?? "",
|
2651
|
-
fileId
|
2652
|
-
},
|
2653
|
-
body: file,
|
2654
|
-
headers: { "Content-Type": contentType }
|
2655
|
-
});
|
2656
|
-
},
|
2657
|
-
delete: async (location) => {
|
2658
|
-
const { table, record, column, fileId = "" } = location ?? {};
|
2659
|
-
return await deleteFileItem({
|
2660
|
-
pathParams: {
|
2661
|
-
workspace: "{workspaceId}",
|
2662
|
-
dbBranchName: "{dbBranch}",
|
2663
|
-
region: "{region}",
|
2664
|
-
tableName: table ?? "",
|
2665
|
-
recordId: record ?? "",
|
2666
|
-
columnName: column ?? "",
|
2667
|
-
fileId
|
2668
|
-
},
|
2669
|
-
...pluginOptions
|
2670
|
-
});
|
2671
|
-
}
|
2672
|
-
};
|
2673
|
-
}
|
2674
|
-
}
|
2675
|
-
function getContentType(file) {
|
2676
|
-
if (typeof file === "string") {
|
2677
|
-
return "text/plain";
|
2678
|
-
}
|
2679
|
-
if (isBlob(file)) {
|
2680
|
-
return file.type;
|
2681
|
-
}
|
2682
|
-
try {
|
2683
|
-
return file.type;
|
2684
|
-
} catch (e) {
|
2685
|
-
}
|
2686
|
-
return "application/octet-stream";
|
2687
|
-
}
|
2688
|
-
|
2689
2675
|
function buildTransformString(transformations) {
|
2690
2676
|
return transformations.flatMap(
|
2691
2677
|
(t) => Object.entries(t).map(([key, value]) => {
|
@@ -2717,16 +2703,18 @@ function transformImage(url, ...transformations) {
|
|
2717
2703
|
class XataFile {
|
2718
2704
|
constructor(file) {
|
2719
2705
|
this.id = file.id;
|
2720
|
-
this.name = file.name
|
2721
|
-
this.mediaType = file.mediaType
|
2706
|
+
this.name = file.name;
|
2707
|
+
this.mediaType = file.mediaType;
|
2722
2708
|
this.base64Content = file.base64Content;
|
2723
|
-
this.enablePublicUrl = file.enablePublicUrl
|
2724
|
-
this.signedUrlTimeout = file.signedUrlTimeout
|
2725
|
-
this.
|
2726
|
-
this.
|
2727
|
-
this.
|
2709
|
+
this.enablePublicUrl = file.enablePublicUrl;
|
2710
|
+
this.signedUrlTimeout = file.signedUrlTimeout;
|
2711
|
+
this.uploadUrlTimeout = file.uploadUrlTimeout;
|
2712
|
+
this.size = file.size;
|
2713
|
+
this.version = file.version;
|
2714
|
+
this.url = file.url;
|
2728
2715
|
this.signedUrl = file.signedUrl;
|
2729
|
-
this.
|
2716
|
+
this.uploadUrl = file.uploadUrl;
|
2717
|
+
this.attributes = file.attributes;
|
2730
2718
|
}
|
2731
2719
|
static fromBuffer(buffer, options = {}) {
|
2732
2720
|
const base64Content = buffer.toString("base64");
|
@@ -2816,7 +2804,7 @@ class XataFile {
|
|
2816
2804
|
const parseInputFileEntry = async (entry) => {
|
2817
2805
|
if (!isDefined(entry))
|
2818
2806
|
return null;
|
2819
|
-
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2807
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
|
2820
2808
|
return compactObject({
|
2821
2809
|
id,
|
2822
2810
|
// Name cannot be an empty string in our API
|
@@ -2824,7 +2812,8 @@ const parseInputFileEntry = async (entry) => {
|
|
2824
2812
|
mediaType,
|
2825
2813
|
base64Content,
|
2826
2814
|
enablePublicUrl,
|
2827
|
-
signedUrlTimeout
|
2815
|
+
signedUrlTimeout,
|
2816
|
+
uploadUrlTimeout
|
2828
2817
|
});
|
2829
2818
|
};
|
2830
2819
|
|
@@ -3695,7 +3684,7 @@ class RestRepository extends Query {
|
|
3695
3684
|
}
|
3696
3685
|
async search(query, options = {}) {
|
3697
3686
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
3698
|
-
const { records } = await searchTable({
|
3687
|
+
const { records, totalCount } = await searchTable({
|
3699
3688
|
pathParams: {
|
3700
3689
|
workspace: "{workspaceId}",
|
3701
3690
|
dbBranchName: "{dbBranch}",
|
@@ -3715,12 +3704,15 @@ class RestRepository extends Query {
|
|
3715
3704
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3716
3705
|
});
|
3717
3706
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3718
|
-
return
|
3707
|
+
return {
|
3708
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3709
|
+
totalCount
|
3710
|
+
};
|
3719
3711
|
});
|
3720
3712
|
}
|
3721
3713
|
async vectorSearch(column, query, options) {
|
3722
3714
|
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3723
|
-
const { records } = await vectorSearchTable({
|
3715
|
+
const { records, totalCount } = await vectorSearchTable({
|
3724
3716
|
pathParams: {
|
3725
3717
|
workspace: "{workspaceId}",
|
3726
3718
|
dbBranchName: "{dbBranch}",
|
@@ -3737,7 +3729,10 @@ class RestRepository extends Query {
|
|
3737
3729
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3738
3730
|
});
|
3739
3731
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3740
|
-
return
|
3732
|
+
return {
|
3733
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3734
|
+
totalCount
|
3735
|
+
};
|
3741
3736
|
});
|
3742
3737
|
}
|
3743
3738
|
async aggregate(aggs, filter) {
|
@@ -3813,7 +3808,13 @@ class RestRepository extends Query {
|
|
3813
3808
|
},
|
3814
3809
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3815
3810
|
});
|
3816
|
-
|
3811
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3812
|
+
return {
|
3813
|
+
...result,
|
3814
|
+
summaries: result.summaries.map(
|
3815
|
+
(summary) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), summary, data.columns ?? [])
|
3816
|
+
)
|
3817
|
+
};
|
3817
3818
|
});
|
3818
3819
|
}
|
3819
3820
|
ask(question, options) {
|
@@ -4184,7 +4185,9 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4184
4185
|
record.delete = function() {
|
4185
4186
|
return db[table].delete(record["id"]);
|
4186
4187
|
};
|
4187
|
-
|
4188
|
+
if (metadata !== void 0) {
|
4189
|
+
record.xata = Object.freeze(metadata);
|
4190
|
+
}
|
4188
4191
|
record.getMetadata = function() {
|
4189
4192
|
return record.xata;
|
4190
4193
|
};
|
@@ -4287,10 +4290,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
4287
4290
|
const startsWith = (value) => ({ $startsWith: value });
|
4288
4291
|
const endsWith = (value) => ({ $endsWith: value });
|
4289
4292
|
const pattern = (value) => ({ $pattern: value });
|
4293
|
+
const iPattern = (value) => ({ $iPattern: value });
|
4290
4294
|
const is = (value) => ({ $is: value });
|
4291
4295
|
const equals = is;
|
4292
4296
|
const isNot = (value) => ({ $isNot: value });
|
4293
4297
|
const contains = (value) => ({ $contains: value });
|
4298
|
+
const iContains = (value) => ({ $iContains: value });
|
4294
4299
|
const includes = (value) => ({ $includes: value });
|
4295
4300
|
const includesAll = (value) => ({ $includesAll: value });
|
4296
4301
|
const includesNone = (value) => ({ $includesNone: value });
|
@@ -4346,6 +4351,80 @@ class SchemaPlugin extends XataPlugin {
|
|
4346
4351
|
_tables = new WeakMap();
|
4347
4352
|
_schemaTables$1 = new WeakMap();
|
4348
4353
|
|
4354
|
+
class FilesPlugin extends XataPlugin {
|
4355
|
+
build(pluginOptions) {
|
4356
|
+
return {
|
4357
|
+
download: async (location) => {
|
4358
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4359
|
+
return await getFileItem({
|
4360
|
+
pathParams: {
|
4361
|
+
workspace: "{workspaceId}",
|
4362
|
+
dbBranchName: "{dbBranch}",
|
4363
|
+
region: "{region}",
|
4364
|
+
tableName: table ?? "",
|
4365
|
+
recordId: record ?? "",
|
4366
|
+
columnName: column ?? "",
|
4367
|
+
fileId
|
4368
|
+
},
|
4369
|
+
...pluginOptions,
|
4370
|
+
rawResponse: true
|
4371
|
+
});
|
4372
|
+
},
|
4373
|
+
upload: async (location, file, options) => {
|
4374
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4375
|
+
const resolvedFile = await file;
|
4376
|
+
const contentType = options?.mediaType || getContentType(resolvedFile);
|
4377
|
+
const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
|
4378
|
+
return await putFileItem({
|
4379
|
+
...pluginOptions,
|
4380
|
+
pathParams: {
|
4381
|
+
workspace: "{workspaceId}",
|
4382
|
+
dbBranchName: "{dbBranch}",
|
4383
|
+
region: "{region}",
|
4384
|
+
tableName: table ?? "",
|
4385
|
+
recordId: record ?? "",
|
4386
|
+
columnName: column ?? "",
|
4387
|
+
fileId
|
4388
|
+
},
|
4389
|
+
body,
|
4390
|
+
headers: { "Content-Type": contentType }
|
4391
|
+
});
|
4392
|
+
},
|
4393
|
+
delete: async (location) => {
|
4394
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4395
|
+
return await deleteFileItem({
|
4396
|
+
pathParams: {
|
4397
|
+
workspace: "{workspaceId}",
|
4398
|
+
dbBranchName: "{dbBranch}",
|
4399
|
+
region: "{region}",
|
4400
|
+
tableName: table ?? "",
|
4401
|
+
recordId: record ?? "",
|
4402
|
+
columnName: column ?? "",
|
4403
|
+
fileId
|
4404
|
+
},
|
4405
|
+
...pluginOptions
|
4406
|
+
});
|
4407
|
+
}
|
4408
|
+
};
|
4409
|
+
}
|
4410
|
+
}
|
4411
|
+
function getContentType(file) {
|
4412
|
+
if (typeof file === "string") {
|
4413
|
+
return "text/plain";
|
4414
|
+
}
|
4415
|
+
if ("mediaType" in file && file.mediaType !== void 0) {
|
4416
|
+
return file.mediaType;
|
4417
|
+
}
|
4418
|
+
if (isBlob(file)) {
|
4419
|
+
return file.type;
|
4420
|
+
}
|
4421
|
+
try {
|
4422
|
+
return file.type;
|
4423
|
+
} catch (e) {
|
4424
|
+
}
|
4425
|
+
return "application/octet-stream";
|
4426
|
+
}
|
4427
|
+
|
4349
4428
|
var __accessCheck$1 = (obj, member, msg) => {
|
4350
4429
|
if (!member.has(obj))
|
4351
4430
|
throw TypeError("Cannot " + msg);
|
@@ -4381,22 +4460,26 @@ class SearchPlugin extends XataPlugin {
|
|
4381
4460
|
build(pluginOptions) {
|
4382
4461
|
return {
|
4383
4462
|
all: async (query, options = {}) => {
|
4384
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4463
|
+
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4385
4464
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4386
|
-
return
|
4387
|
-
|
4388
|
-
|
4389
|
-
|
4465
|
+
return {
|
4466
|
+
totalCount,
|
4467
|
+
records: records.map((record) => {
|
4468
|
+
const { table = "orphan" } = record.xata;
|
4469
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
4470
|
+
})
|
4471
|
+
};
|
4390
4472
|
},
|
4391
4473
|
byTable: async (query, options = {}) => {
|
4392
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4474
|
+
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4393
4475
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4394
|
-
|
4476
|
+
const records = rawRecords.reduce((acc, record) => {
|
4395
4477
|
const { table = "orphan" } = record.xata;
|
4396
4478
|
const items = acc[table] ?? [];
|
4397
4479
|
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
4398
4480
|
return { ...acc, [table]: [...items, item] };
|
4399
4481
|
}, {});
|
4482
|
+
return { totalCount, records };
|
4400
4483
|
}
|
4401
4484
|
};
|
4402
4485
|
}
|
@@ -4405,13 +4488,13 @@ _schemaTables = new WeakMap();
|
|
4405
4488
|
_search = new WeakSet();
|
4406
4489
|
search_fn = async function(query, options, pluginOptions) {
|
4407
4490
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
4408
|
-
const { records } = await searchBranch({
|
4491
|
+
const { records, totalCount } = await searchBranch({
|
4409
4492
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4410
4493
|
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
4411
4494
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
4412
4495
|
...pluginOptions
|
4413
4496
|
});
|
4414
|
-
return records;
|
4497
|
+
return { records, totalCount };
|
4415
4498
|
};
|
4416
4499
|
_getSchemaTables = new WeakSet();
|
4417
4500
|
getSchemaTables_fn = async function(pluginOptions) {
|
@@ -4721,21 +4804,6 @@ const deserialize = (json) => {
|
|
4721
4804
|
return defaultSerializer.fromJSON(json);
|
4722
4805
|
};
|
4723
4806
|
|
4724
|
-
function buildWorkerRunner(config) {
|
4725
|
-
return function xataWorker(name, worker) {
|
4726
|
-
return async (...args) => {
|
4727
|
-
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
4728
|
-
const result = await fetch(url, {
|
4729
|
-
method: "POST",
|
4730
|
-
headers: { "Content-Type": "application/json" },
|
4731
|
-
body: serialize({ args })
|
4732
|
-
});
|
4733
|
-
const text = await result.text();
|
4734
|
-
return deserialize(text);
|
4735
|
-
};
|
4736
|
-
};
|
4737
|
-
}
|
4738
|
-
|
4739
4807
|
class XataError extends Error {
|
4740
4808
|
constructor(message, status) {
|
4741
4809
|
super(message);
|
@@ -4743,5 +4811,5 @@ class XataError extends Error {
|
|
4743
4811
|
}
|
4744
4812
|
}
|
4745
4813
|
|
4746
|
-
export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString,
|
4814
|
+
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, fileUpload, 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, pgRollJobStatus, pgRollMigrationHistory, 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 };
|
4747
4815
|
//# sourceMappingURL=index.mjs.map
|