@xata.io/client 0.28.2 → 0.28.4

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/dist/index.mjs CHANGED
@@ -526,7 +526,7 @@ function defaultOnOpen(response) {
526
526
  }
527
527
  }
528
528
 
529
- const VERSION = "0.28.2";
529
+ const VERSION = "0.28.4";
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
- const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
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, {
@@ -779,6 +858,7 @@ const pgRollJobStatus = (variables, signal) => dataPlaneFetch({
779
858
  ...variables,
780
859
  signal
781
860
  });
861
+ const pgRollMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/migrations", method: "get", ...variables, signal });
782
862
  const getBranchList = (variables, signal) => dataPlaneFetch({
783
863
  url: "/dbs/{dbName}",
784
864
  method: "get",
@@ -985,6 +1065,12 @@ const fileAccess = (variables, signal) => dataPlaneFetch({
985
1065
  ...variables,
986
1066
  signal
987
1067
  });
1068
+ const fileUpload = (variables, signal) => dataPlaneFetch({
1069
+ url: "/file/{fileId}",
1070
+ method: "put",
1071
+ ...variables,
1072
+ signal
1073
+ });
988
1074
  const sqlQuery = (variables, signal) => dataPlaneFetch({
989
1075
  url: "/db/{dbBranchName}/sql",
990
1076
  method: "post",
@@ -996,6 +1082,7 @@ const operationsByTag$2 = {
996
1082
  applyMigration,
997
1083
  pgRollStatus,
998
1084
  pgRollJobStatus,
1085
+ pgRollMigrationHistory,
999
1086
  getBranchList,
1000
1087
  getBranchDetails,
1001
1088
  createBranch,
@@ -1054,7 +1141,7 @@ const operationsByTag$2 = {
1054
1141
  deleteRecord,
1055
1142
  bulkInsertTableRecords
1056
1143
  },
1057
- files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
1144
+ files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
1058
1145
  searchAndFilter: {
1059
1146
  queryTable,
1060
1147
  searchBranch,
@@ -1176,12 +1263,7 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
1176
1263
  const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
1177
1264
  const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
1178
1265
  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
- });
1266
+ const listClusters = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "get", ...variables, signal });
1185
1267
  const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
1186
1268
  const getCluster = (variables, signal) => controlPlaneFetch({
1187
1269
  url: "/workspaces/{workspaceId}/clusters/{clusterId}",
@@ -1261,61 +1343,6 @@ const operationsByTag$1 = {
1261
1343
 
1262
1344
  const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
1263
1345
 
1264
- function getHostUrl(provider, type) {
1265
- if (isHostProviderAlias(provider)) {
1266
- return providers[provider][type];
1267
- } else if (isHostProviderBuilder(provider)) {
1268
- return provider[type];
1269
- }
1270
- throw new Error("Invalid API provider");
1271
- }
1272
- const providers = {
1273
- production: {
1274
- main: "https://api.xata.io",
1275
- workspaces: "https://{workspaceId}.{region}.xata.sh"
1276
- },
1277
- staging: {
1278
- main: "https://api.staging-xata.dev",
1279
- workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
1280
- },
1281
- dev: {
1282
- main: "https://api.dev-xata.dev",
1283
- workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
1284
- }
1285
- };
1286
- function isHostProviderAlias(alias) {
1287
- return isString(alias) && Object.keys(providers).includes(alias);
1288
- }
1289
- function isHostProviderBuilder(builder) {
1290
- return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
1291
- }
1292
- function parseProviderString(provider = "production") {
1293
- if (isHostProviderAlias(provider)) {
1294
- return provider;
1295
- }
1296
- const [main, workspaces] = provider.split(",");
1297
- if (!main || !workspaces)
1298
- return null;
1299
- return { main, workspaces };
1300
- }
1301
- function buildProviderString(provider) {
1302
- if (isHostProviderAlias(provider))
1303
- return provider;
1304
- return `${provider.main},${provider.workspaces}`;
1305
- }
1306
- function parseWorkspacesUrlParts(url) {
1307
- if (!isString(url))
1308
- return null;
1309
- const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
1310
- const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
1311
- const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
1312
- const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
1313
- const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
1314
- if (!match)
1315
- return null;
1316
- return { workspace: match[1], region: match[2] };
1317
- }
1318
-
1319
1346
  var __accessCheck$7 = (obj, member, msg) => {
1320
1347
  if (!member.has(obj))
1321
1348
  throw TypeError("Cannot " + msg);
@@ -2676,10 +2703,12 @@ class XataFile {
2676
2703
  this.base64Content = file.base64Content;
2677
2704
  this.enablePublicUrl = file.enablePublicUrl;
2678
2705
  this.signedUrlTimeout = file.signedUrlTimeout;
2706
+ this.uploadUrlTimeout = file.uploadUrlTimeout;
2679
2707
  this.size = file.size;
2680
2708
  this.version = file.version;
2681
2709
  this.url = file.url;
2682
2710
  this.signedUrl = file.signedUrl;
2711
+ this.uploadUrl = file.uploadUrl;
2683
2712
  this.attributes = file.attributes;
2684
2713
  }
2685
2714
  static fromBuffer(buffer, options = {}) {
@@ -2770,7 +2799,7 @@ class XataFile {
2770
2799
  const parseInputFileEntry = async (entry) => {
2771
2800
  if (!isDefined(entry))
2772
2801
  return null;
2773
- const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
2802
+ const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
2774
2803
  return compactObject({
2775
2804
  id,
2776
2805
  // Name cannot be an empty string in our API
@@ -2778,7 +2807,8 @@ const parseInputFileEntry = async (entry) => {
2778
2807
  mediaType,
2779
2808
  base64Content,
2780
2809
  enablePublicUrl,
2781
- signedUrlTimeout
2810
+ signedUrlTimeout,
2811
+ uploadUrlTimeout
2782
2812
  });
2783
2813
  };
2784
2814
 
@@ -4776,5 +4806,5 @@ class XataError extends Error {
4776
4806
  }
4777
4807
  }
4778
4808
 
4779
- export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, pgRollJobStatus, 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 };
4809
+ 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 };
4780
4810
  //# sourceMappingURL=index.mjs.map