@xata.io/client 0.25.0 → 0.25.1

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
@@ -86,6 +86,18 @@ function chunk(array, chunkSize) {
86
86
  async function timeout(ms) {
87
87
  return new Promise((resolve) => setTimeout(resolve, ms));
88
88
  }
89
+ function timeoutWithCancel(ms) {
90
+ let timeoutId;
91
+ const promise = new Promise((resolve) => {
92
+ timeoutId = setTimeout(() => {
93
+ resolve();
94
+ }, ms);
95
+ });
96
+ return {
97
+ cancel: () => clearTimeout(timeoutId),
98
+ promise
99
+ };
100
+ }
89
101
  function promiseMap(inputValues, mapper) {
90
102
  const reducer = (acc$, inputValue) => acc$.then(
91
103
  (acc) => mapper(inputValue).then((result) => {
@@ -288,7 +300,8 @@ class ApiRequestPool {
288
300
  const start = /* @__PURE__ */ new Date();
289
301
  const fetchImpl = this.getFetch();
290
302
  const runRequest = async (stalled = false) => {
291
- const response = await Promise.race([fetchImpl(url, options), timeout(REQUEST_TIMEOUT).then(() => null)]);
303
+ const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
304
+ const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
292
305
  if (!response) {
293
306
  throw new Error("Request timed out");
294
307
  }
@@ -514,7 +527,7 @@ function defaultOnOpen(response) {
514
527
  }
515
528
  }
516
529
 
517
- const VERSION = "0.25.0";
530
+ const VERSION = "0.25.1";
518
531
 
519
532
  var __defProp$7 = Object.defineProperty;
520
533
  var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;