@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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @xata.io/client@0.28.2 add-version /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.28.3 add-version /home/runner/work/client-ts/client-ts/packages/client
3
3
  > node ../../scripts/add-version-file.mjs
4
4
 
@@ -1,13 +1,13 @@
1
1
 
2
- > @xata.io/client@0.28.2 build /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.28.3 build /home/runner/work/client-ts/client-ts/packages/client
3
3
  > rimraf dist && rollup -c
4
4
 
5
5
  
6
6
  src/index.ts → dist/index.cjs...
7
- created dist/index.cjs in 756ms
7
+ created dist/index.cjs in 742ms
8
8
  
9
9
  src/index.ts → dist/index.mjs...
10
- created dist/index.mjs in 471ms
10
+ created dist/index.mjs in 472ms
11
11
  
12
12
  src/index.ts → dist/index.d.ts...
13
- created dist/index.d.ts in 5.5s
13
+ created dist/index.d.ts in 5.2s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.28.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1304](https://github.com/xataio/client-ts/pull/1304) [`b7f3ec9`](https://github.com/xataio/client-ts/commit/b7f3ec9eabe3642929131e244bd774f4d3134482) Thanks [@SferaDev](https://github.com/SferaDev)! - Rewrite upload url path
8
+
3
9
  ## 0.28.2
4
10
 
5
11
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -528,7 +528,7 @@ function defaultOnOpen(response) {
528
528
  }
529
529
  }
530
530
 
531
- const VERSION = "0.28.2";
531
+ const VERSION = "0.28.3";
532
532
 
533
533
  class ErrorWithCause extends Error {
534
534
  constructor(message, options) {
@@ -571,6 +571,62 @@ 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
+ };
596
+ function isHostProviderAlias(alias) {
597
+ return isString(alias) && Object.keys(providers).includes(alias);
598
+ }
599
+ function isHostProviderBuilder(builder) {
600
+ return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
601
+ }
602
+ function parseProviderString(provider = "production") {
603
+ if (isHostProviderAlias(provider)) {
604
+ return provider;
605
+ }
606
+ const [main, workspaces] = provider.split(",");
607
+ if (!main || !workspaces)
608
+ return null;
609
+ return { main, workspaces };
610
+ }
611
+ function buildProviderString(provider) {
612
+ if (isHostProviderAlias(provider))
613
+ return provider;
614
+ return `${provider.main},${provider.workspaces}`;
615
+ }
616
+ function parseWorkspacesUrlParts(url) {
617
+ if (!isString(url))
618
+ return null;
619
+ const matches = {
620
+ production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/),
621
+ staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
622
+ dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/)
623
+ };
624
+ const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
625
+ if (!isHostProviderAlias(host) || !match)
626
+ return null;
627
+ return { workspace: match[1], region: match[2], host };
628
+ }
629
+
574
630
  const pool = new ApiRequestPool();
575
631
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
576
632
  const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
@@ -586,6 +642,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
586
642
  return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
587
643
  };
588
644
  function buildBaseUrl({
645
+ method,
589
646
  endpoint,
590
647
  path,
591
648
  workspacesApiUrl,
@@ -593,7 +650,24 @@ function buildBaseUrl({
593
650
  pathParams = {}
594
651
  }) {
595
652
  if (endpoint === "dataPlane") {
596
- const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
653
+ let url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
654
+ if (method.toUpperCase() === "PUT" && [
655
+ "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
656
+ "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}"
657
+ ].includes(path)) {
658
+ const { host } = parseWorkspacesUrlParts(url) ?? {};
659
+ switch (host) {
660
+ case "production":
661
+ url = url.replace("xata.sh", "upload.xata.sh");
662
+ break;
663
+ case "staging":
664
+ url = url.replace("staging-xata.dev", "upload.staging-xata.dev");
665
+ break;
666
+ case "dev":
667
+ url = url.replace("dev-xata.dev", "upload.dev-xata.dev");
668
+ break;
669
+ }
670
+ }
597
671
  const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
598
672
  return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
599
673
  }
@@ -642,7 +716,7 @@ async function fetch$1({
642
716
  return await trace(
643
717
  `${method.toUpperCase()} ${path}`,
644
718
  async ({ setAttributes }) => {
645
- const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
719
+ const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
646
720
  const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
647
721
  const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
648
722
  setAttributes({
@@ -725,7 +799,7 @@ function fetchSSERequest({
725
799
  clientName,
726
800
  xataAgentExtra
727
801
  }) {
728
- const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
802
+ const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
729
803
  const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
730
804
  const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
731
805
  void fetchEventSource(url, {
@@ -987,6 +1061,12 @@ const fileAccess = (variables, signal) => dataPlaneFetch({
987
1061
  ...variables,
988
1062
  signal
989
1063
  });
1064
+ const fileUpload = (variables, signal) => dataPlaneFetch({
1065
+ url: "/file/{fileId}",
1066
+ method: "put",
1067
+ ...variables,
1068
+ signal
1069
+ });
990
1070
  const sqlQuery = (variables, signal) => dataPlaneFetch({
991
1071
  url: "/db/{dbBranchName}/sql",
992
1072
  method: "post",
@@ -1056,7 +1136,7 @@ const operationsByTag$2 = {
1056
1136
  deleteRecord,
1057
1137
  bulkInsertTableRecords
1058
1138
  },
1059
- files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
1139
+ files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
1060
1140
  searchAndFilter: {
1061
1141
  queryTable,
1062
1142
  searchBranch,
@@ -1263,61 +1343,6 @@ const operationsByTag$1 = {
1263
1343
 
1264
1344
  const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
1265
1345
 
1266
- function getHostUrl(provider, type) {
1267
- if (isHostProviderAlias(provider)) {
1268
- return providers[provider][type];
1269
- } else if (isHostProviderBuilder(provider)) {
1270
- return provider[type];
1271
- }
1272
- throw new Error("Invalid API provider");
1273
- }
1274
- const providers = {
1275
- production: {
1276
- main: "https://api.xata.io",
1277
- workspaces: "https://{workspaceId}.{region}.xata.sh"
1278
- },
1279
- staging: {
1280
- main: "https://api.staging-xata.dev",
1281
- workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
1282
- },
1283
- dev: {
1284
- main: "https://api.dev-xata.dev",
1285
- workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
1286
- }
1287
- };
1288
- function isHostProviderAlias(alias) {
1289
- return isString(alias) && Object.keys(providers).includes(alias);
1290
- }
1291
- function isHostProviderBuilder(builder) {
1292
- return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
1293
- }
1294
- function parseProviderString(provider = "production") {
1295
- if (isHostProviderAlias(provider)) {
1296
- return provider;
1297
- }
1298
- const [main, workspaces] = provider.split(",");
1299
- if (!main || !workspaces)
1300
- return null;
1301
- return { main, workspaces };
1302
- }
1303
- function buildProviderString(provider) {
1304
- if (isHostProviderAlias(provider))
1305
- return provider;
1306
- return `${provider.main},${provider.workspaces}`;
1307
- }
1308
- function parseWorkspacesUrlParts(url) {
1309
- if (!isString(url))
1310
- return null;
1311
- const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
1312
- const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
1313
- const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
1314
- const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
1315
- const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
1316
- if (!match)
1317
- return null;
1318
- return { workspace: match[1], region: match[2] };
1319
- }
1320
-
1321
1346
  var __accessCheck$7 = (obj, member, msg) => {
1322
1347
  if (!member.has(obj))
1323
1348
  throw TypeError("Cannot " + msg);
@@ -2678,10 +2703,12 @@ class XataFile {
2678
2703
  this.base64Content = file.base64Content;
2679
2704
  this.enablePublicUrl = file.enablePublicUrl;
2680
2705
  this.signedUrlTimeout = file.signedUrlTimeout;
2706
+ this.uploadUrlTimeout = file.uploadUrlTimeout;
2681
2707
  this.size = file.size;
2682
2708
  this.version = file.version;
2683
2709
  this.url = file.url;
2684
2710
  this.signedUrl = file.signedUrl;
2711
+ this.uploadUrl = file.uploadUrl;
2685
2712
  this.attributes = file.attributes;
2686
2713
  }
2687
2714
  static fromBuffer(buffer, options = {}) {
@@ -2772,7 +2799,7 @@ class XataFile {
2772
2799
  const parseInputFileEntry = async (entry) => {
2773
2800
  if (!isDefined(entry))
2774
2801
  return null;
2775
- const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
2802
+ const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
2776
2803
  return compactObject({
2777
2804
  id,
2778
2805
  // Name cannot be an empty string in our API
@@ -2780,7 +2807,8 @@ const parseInputFileEntry = async (entry) => {
2780
2807
  mediaType,
2781
2808
  base64Content,
2782
2809
  enablePublicUrl,
2783
- signedUrlTimeout
2810
+ signedUrlTimeout,
2811
+ uploadUrlTimeout
2784
2812
  });
2785
2813
  };
2786
2814
 
@@ -4848,6 +4876,7 @@ exports.equals = equals;
4848
4876
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
4849
4877
  exports.exists = exists;
4850
4878
  exports.fileAccess = fileAccess;
4879
+ exports.fileUpload = fileUpload;
4851
4880
  exports.ge = ge;
4852
4881
  exports.getAPIKey = getAPIKey;
4853
4882
  exports.getAuthorizationCode = getAuthorizationCode;