@xata.io/client 0.28.1 → 0.28.3

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.1";
529
+ const VERSION = "0.28.3";
530
530
 
531
531
  class ErrorWithCause extends Error {
532
532
  constructor(message, options) {
@@ -569,6 +569,62 @@ 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
+ };
594
+ function isHostProviderAlias(alias) {
595
+ return isString(alias) && Object.keys(providers).includes(alias);
596
+ }
597
+ function isHostProviderBuilder(builder) {
598
+ return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
599
+ }
600
+ function parseProviderString(provider = "production") {
601
+ if (isHostProviderAlias(provider)) {
602
+ return provider;
603
+ }
604
+ const [main, workspaces] = provider.split(",");
605
+ if (!main || !workspaces)
606
+ return null;
607
+ return { main, workspaces };
608
+ }
609
+ function buildProviderString(provider) {
610
+ if (isHostProviderAlias(provider))
611
+ return provider;
612
+ return `${provider.main},${provider.workspaces}`;
613
+ }
614
+ function parseWorkspacesUrlParts(url) {
615
+ if (!isString(url))
616
+ return null;
617
+ const matches = {
618
+ production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/),
619
+ staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
620
+ dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/)
621
+ };
622
+ const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
623
+ if (!isHostProviderAlias(host) || !match)
624
+ return null;
625
+ return { workspace: match[1], region: match[2], host };
626
+ }
627
+
572
628
  const pool = new ApiRequestPool();
573
629
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
574
630
  const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
@@ -584,6 +640,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
584
640
  return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
585
641
  };
586
642
  function buildBaseUrl({
643
+ method,
587
644
  endpoint,
588
645
  path,
589
646
  workspacesApiUrl,
@@ -591,7 +648,24 @@ function buildBaseUrl({
591
648
  pathParams = {}
592
649
  }) {
593
650
  if (endpoint === "dataPlane") {
594
- const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
651
+ let url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
652
+ if (method.toUpperCase() === "PUT" && [
653
+ "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
654
+ "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}"
655
+ ].includes(path)) {
656
+ const { host } = parseWorkspacesUrlParts(url) ?? {};
657
+ switch (host) {
658
+ case "production":
659
+ url = url.replace("xata.sh", "upload.xata.sh");
660
+ break;
661
+ case "staging":
662
+ url = url.replace("staging-xata.dev", "upload.staging-xata.dev");
663
+ break;
664
+ case "dev":
665
+ url = url.replace("dev-xata.dev", "upload.dev-xata.dev");
666
+ break;
667
+ }
668
+ }
595
669
  const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
596
670
  return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
597
671
  }
@@ -640,7 +714,7 @@ async function fetch$1({
640
714
  return await trace(
641
715
  `${method.toUpperCase()} ${path}`,
642
716
  async ({ setAttributes }) => {
643
- const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
717
+ const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
644
718
  const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
645
719
  const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
646
720
  setAttributes({
@@ -723,7 +797,7 @@ function fetchSSERequest({
723
797
  clientName,
724
798
  xataAgentExtra
725
799
  }) {
726
- const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
800
+ const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
727
801
  const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
728
802
  const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
729
803
  void fetchEventSource(url, {
@@ -773,6 +847,12 @@ const pgRollStatus = (variables, signal) => dataPlaneFetch({
773
847
  ...variables,
774
848
  signal
775
849
  });
850
+ const pgRollJobStatus = (variables, signal) => dataPlaneFetch({
851
+ url: "/db/{dbBranchName}/pgroll/jobs/{jobId}",
852
+ method: "get",
853
+ ...variables,
854
+ signal
855
+ });
776
856
  const getBranchList = (variables, signal) => dataPlaneFetch({
777
857
  url: "/dbs/{dbName}",
778
858
  method: "get",
@@ -979,6 +1059,12 @@ const fileAccess = (variables, signal) => dataPlaneFetch({
979
1059
  ...variables,
980
1060
  signal
981
1061
  });
1062
+ const fileUpload = (variables, signal) => dataPlaneFetch({
1063
+ url: "/file/{fileId}",
1064
+ method: "put",
1065
+ ...variables,
1066
+ signal
1067
+ });
982
1068
  const sqlQuery = (variables, signal) => dataPlaneFetch({
983
1069
  url: "/db/{dbBranchName}/sql",
984
1070
  method: "post",
@@ -989,6 +1075,7 @@ const operationsByTag$2 = {
989
1075
  branch: {
990
1076
  applyMigration,
991
1077
  pgRollStatus,
1078
+ pgRollJobStatus,
992
1079
  getBranchList,
993
1080
  getBranchDetails,
994
1081
  createBranch,
@@ -1047,7 +1134,7 @@ const operationsByTag$2 = {
1047
1134
  deleteRecord,
1048
1135
  bulkInsertTableRecords
1049
1136
  },
1050
- files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
1137
+ files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
1051
1138
  searchAndFilter: {
1052
1139
  queryTable,
1053
1140
  searchBranch,
@@ -1254,61 +1341,6 @@ const operationsByTag$1 = {
1254
1341
 
1255
1342
  const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
1256
1343
 
1257
- function getHostUrl(provider, type) {
1258
- if (isHostProviderAlias(provider)) {
1259
- return providers[provider][type];
1260
- } else if (isHostProviderBuilder(provider)) {
1261
- return provider[type];
1262
- }
1263
- throw new Error("Invalid API provider");
1264
- }
1265
- const providers = {
1266
- production: {
1267
- main: "https://api.xata.io",
1268
- workspaces: "https://{workspaceId}.{region}.xata.sh"
1269
- },
1270
- staging: {
1271
- main: "https://api.staging-xata.dev",
1272
- workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
1273
- },
1274
- dev: {
1275
- main: "https://api.dev-xata.dev",
1276
- workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
1277
- }
1278
- };
1279
- function isHostProviderAlias(alias) {
1280
- return isString(alias) && Object.keys(providers).includes(alias);
1281
- }
1282
- function isHostProviderBuilder(builder) {
1283
- return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
1284
- }
1285
- function parseProviderString(provider = "production") {
1286
- if (isHostProviderAlias(provider)) {
1287
- return provider;
1288
- }
1289
- const [main, workspaces] = provider.split(",");
1290
- if (!main || !workspaces)
1291
- return null;
1292
- return { main, workspaces };
1293
- }
1294
- function buildProviderString(provider) {
1295
- if (isHostProviderAlias(provider))
1296
- return provider;
1297
- return `${provider.main},${provider.workspaces}`;
1298
- }
1299
- function parseWorkspacesUrlParts(url) {
1300
- if (!isString(url))
1301
- return null;
1302
- const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
1303
- const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
1304
- const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
1305
- const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
1306
- const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
1307
- if (!match)
1308
- return null;
1309
- return { workspace: match[1], region: match[2] };
1310
- }
1311
-
1312
1344
  var __accessCheck$7 = (obj, member, msg) => {
1313
1345
  if (!member.has(obj))
1314
1346
  throw TypeError("Cannot " + msg);
@@ -2669,10 +2701,12 @@ class XataFile {
2669
2701
  this.base64Content = file.base64Content;
2670
2702
  this.enablePublicUrl = file.enablePublicUrl;
2671
2703
  this.signedUrlTimeout = file.signedUrlTimeout;
2704
+ this.uploadUrlTimeout = file.uploadUrlTimeout;
2672
2705
  this.size = file.size;
2673
2706
  this.version = file.version;
2674
2707
  this.url = file.url;
2675
2708
  this.signedUrl = file.signedUrl;
2709
+ this.uploadUrl = file.uploadUrl;
2676
2710
  this.attributes = file.attributes;
2677
2711
  }
2678
2712
  static fromBuffer(buffer, options = {}) {
@@ -2763,7 +2797,7 @@ class XataFile {
2763
2797
  const parseInputFileEntry = async (entry) => {
2764
2798
  if (!isDefined(entry))
2765
2799
  return null;
2766
- const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
2800
+ const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
2767
2801
  return compactObject({
2768
2802
  id,
2769
2803
  // Name cannot be an empty string in our API
@@ -2771,7 +2805,8 @@ const parseInputFileEntry = async (entry) => {
2771
2805
  mediaType,
2772
2806
  base64Content,
2773
2807
  enablePublicUrl,
2774
- signedUrlTimeout
2808
+ signedUrlTimeout,
2809
+ uploadUrlTimeout
2775
2810
  });
2776
2811
  };
2777
2812
 
@@ -4769,5 +4804,5 @@ class XataError extends Error {
4769
4804
  }
4770
4805
  }
4771
4806
 
4772
- export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, pgRollStatus, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
4807
+ 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, 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 };
4773
4808
  //# sourceMappingURL=index.mjs.map