@xata.io/client 0.28.2 → 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.2";
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, {
@@ -985,6 +1059,12 @@ const fileAccess = (variables, signal) => dataPlaneFetch({
985
1059
  ...variables,
986
1060
  signal
987
1061
  });
1062
+ const fileUpload = (variables, signal) => dataPlaneFetch({
1063
+ url: "/file/{fileId}",
1064
+ method: "put",
1065
+ ...variables,
1066
+ signal
1067
+ });
988
1068
  const sqlQuery = (variables, signal) => dataPlaneFetch({
989
1069
  url: "/db/{dbBranchName}/sql",
990
1070
  method: "post",
@@ -1054,7 +1134,7 @@ const operationsByTag$2 = {
1054
1134
  deleteRecord,
1055
1135
  bulkInsertTableRecords
1056
1136
  },
1057
- files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
1137
+ files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
1058
1138
  searchAndFilter: {
1059
1139
  queryTable,
1060
1140
  searchBranch,
@@ -1261,61 +1341,6 @@ const operationsByTag$1 = {
1261
1341
 
1262
1342
  const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
1263
1343
 
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
1344
  var __accessCheck$7 = (obj, member, msg) => {
1320
1345
  if (!member.has(obj))
1321
1346
  throw TypeError("Cannot " + msg);
@@ -2676,10 +2701,12 @@ class XataFile {
2676
2701
  this.base64Content = file.base64Content;
2677
2702
  this.enablePublicUrl = file.enablePublicUrl;
2678
2703
  this.signedUrlTimeout = file.signedUrlTimeout;
2704
+ this.uploadUrlTimeout = file.uploadUrlTimeout;
2679
2705
  this.size = file.size;
2680
2706
  this.version = file.version;
2681
2707
  this.url = file.url;
2682
2708
  this.signedUrl = file.signedUrl;
2709
+ this.uploadUrl = file.uploadUrl;
2683
2710
  this.attributes = file.attributes;
2684
2711
  }
2685
2712
  static fromBuffer(buffer, options = {}) {
@@ -2770,7 +2797,7 @@ class XataFile {
2770
2797
  const parseInputFileEntry = async (entry) => {
2771
2798
  if (!isDefined(entry))
2772
2799
  return null;
2773
- const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
2800
+ const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
2774
2801
  return compactObject({
2775
2802
  id,
2776
2803
  // Name cannot be an empty string in our API
@@ -2778,7 +2805,8 @@ const parseInputFileEntry = async (entry) => {
2778
2805
  mediaType,
2779
2806
  base64Content,
2780
2807
  enablePublicUrl,
2781
- signedUrlTimeout
2808
+ signedUrlTimeout,
2809
+ uploadUrlTimeout
2782
2810
  });
2783
2811
  };
2784
2812
 
@@ -4776,5 +4804,5 @@ class XataError extends Error {
4776
4804
  }
4777
4805
  }
4778
4806
 
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 };
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 };
4780
4808
  //# sourceMappingURL=index.mjs.map