@liveblocks/core 2.8.0-beta1 → 2.8.0-beta2

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
@@ -6,7 +6,7 @@ var __export = (target, all) => {
6
6
 
7
7
  // src/version.ts
8
8
  var PKG_NAME = "@liveblocks/core";
9
- var PKG_VERSION = "2.8.0-beta1";
9
+ var PKG_VERSION = "2.8.0-beta2";
10
10
  var PKG_FORMAT = "esm";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -4795,6 +4795,28 @@ function findNonSerializableValue(value, path = "") {
4795
4795
  return false;
4796
4796
  }
4797
4797
 
4798
+ // src/lib/autoRetry.ts
4799
+ async function autoRetry(promiseFn, maxTries, backoff, exitCondition) {
4800
+ const fallbackBackoff = backoff.length > 0 ? backoff[backoff.length - 1] : 0;
4801
+ let attempt = 0;
4802
+ while (true) {
4803
+ attempt++;
4804
+ const promise = promiseFn();
4805
+ try {
4806
+ return await promise;
4807
+ } catch (err) {
4808
+ if (exitCondition && exitCondition(err)) {
4809
+ throw err;
4810
+ }
4811
+ if (attempt >= maxTries) {
4812
+ throw new Error(`Failed after ${maxTries} attempts: ${String(err)}`);
4813
+ }
4814
+ }
4815
+ const delay = backoff[attempt - 1] ?? fallbackBackoff;
4816
+ await wait(delay);
4817
+ }
4818
+ }
4819
+
4798
4820
  // src/lib/chunk.ts
4799
4821
  function chunk(array, size) {
4800
4822
  const chunks = [];
@@ -6700,25 +6722,51 @@ ${Array.from(traces).join("\n\n")}`
6700
6722
  throw abortError;
6701
6723
  }
6702
6724
  if (attachment.size <= ATTACHMENT_PART_SIZE) {
6703
- return fetchCommentsJson(
6704
- `/attachments/${encodeURIComponent(attachment.id)}/upload/${encodeURIComponent(attachment.name)}`,
6705
- {
6706
- method: "PUT",
6707
- body: attachment.file,
6708
- signal: abortSignal
6725
+ return autoRetry(
6726
+ () => fetchCommentsJson(
6727
+ `/attachments/${encodeURIComponent(attachment.id)}/upload/${encodeURIComponent(attachment.name)}`,
6728
+ {
6729
+ method: "PUT",
6730
+ body: attachment.file,
6731
+ signal: abortSignal
6732
+ },
6733
+ {
6734
+ fileSize: attachment.size
6735
+ }
6736
+ ),
6737
+ 10,
6738
+ [2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3],
6739
+ () => {
6740
+ if (abortSignal?.aborted) {
6741
+ throw abortError;
6742
+ }
6743
+ return false;
6709
6744
  }
6710
6745
  );
6711
6746
  } else {
6712
6747
  let uploadId;
6713
6748
  const uploadedParts = [];
6714
- try {
6715
- const createMultiPartUpload = await fetchCommentsJson(
6749
+ const createMultiPartUpload = await autoRetry(
6750
+ () => fetchCommentsJson(
6716
6751
  `/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(attachment.name)}`,
6717
6752
  {
6718
6753
  method: "POST",
6719
6754
  signal: abortSignal
6755
+ },
6756
+ {
6757
+ fileSize: attachment.size
6720
6758
  }
6721
- );
6759
+ ),
6760
+ 10,
6761
+ [2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3],
6762
+ () => {
6763
+ if (abortSignal?.aborted) {
6764
+ throw abortError;
6765
+ }
6766
+ return false;
6767
+ }
6768
+ );
6769
+ try {
6722
6770
  uploadId = createMultiPartUpload.uploadId;
6723
6771
  const parts = splitFileIntoParts(attachment.file);
6724
6772
  if (abortSignal?.aborted) {
@@ -6729,12 +6777,22 @@ ${Array.from(traces).join("\n\n")}`
6729
6777
  const uploadedPartsPromises = [];
6730
6778
  for (const { part, partNumber } of parts2) {
6731
6779
  uploadedPartsPromises.push(
6732
- fetchCommentsJson(
6733
- `/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(uploadId)}/${encodeURIComponent(partNumber)}`,
6734
- {
6735
- method: "PUT",
6736
- body: part,
6737
- signal: abortSignal
6780
+ autoRetry(
6781
+ () => fetchCommentsJson(
6782
+ `/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(createMultiPartUpload.uploadId)}/${encodeURIComponent(partNumber)}`,
6783
+ {
6784
+ method: "PUT",
6785
+ body: part,
6786
+ signal: abortSignal
6787
+ }
6788
+ ),
6789
+ 10,
6790
+ [2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3],
6791
+ () => {
6792
+ if (abortSignal?.aborted) {
6793
+ throw abortError;
6794
+ }
6795
+ return false;
6738
6796
  }
6739
6797
  )
6740
6798
  );
@@ -6760,13 +6818,16 @@ ${Array.from(traces).join("\n\n")}`
6760
6818
  );
6761
6819
  } catch (error3) {
6762
6820
  if (uploadId && error3?.name && (error3.name === "AbortError" || error3.name === "TimeoutError")) {
6763
- await fetchCommentsApi(
6764
- `/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(uploadId)}`,
6765
- void 0,
6766
- {
6767
- method: "DELETE"
6768
- }
6769
- );
6821
+ try {
6822
+ await fetchCommentsApi(
6823
+ `/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(uploadId)}`,
6824
+ void 0,
6825
+ {
6826
+ method: "DELETE"
6827
+ }
6828
+ );
6829
+ } catch (error4) {
6830
+ }
6770
6831
  }
6771
6832
  throw error3;
6772
6833
  }
@@ -8179,6 +8240,7 @@ export {
8179
8240
  asPos,
8180
8241
  assert,
8181
8242
  assertNever,
8243
+ autoRetry,
8182
8244
  b64decode,
8183
8245
  chunk,
8184
8246
  cloneLson,