@liveblocks/core 2.8.0-beta1 → 2.8.0-beta3
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.d.mts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +122 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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-
|
|
9
|
+
var PKG_VERSION = "2.8.0-beta3";
|
|
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 = [];
|
|
@@ -5226,6 +5248,19 @@ function installBackgroundTabSpy() {
|
|
|
5226
5248
|
var GET_ATTACHMENT_URLS_BATCH_DELAY = 50;
|
|
5227
5249
|
var ATTACHMENT_PART_SIZE = 5 * 1024 * 1024;
|
|
5228
5250
|
var ATTACHMENT_PART_BATCH_SIZE = 5;
|
|
5251
|
+
var RETRY_ATTEMPTS = 10;
|
|
5252
|
+
var RETRY_DELAYS = [
|
|
5253
|
+
2e3,
|
|
5254
|
+
2e3,
|
|
5255
|
+
2e3,
|
|
5256
|
+
2e3,
|
|
5257
|
+
2e3,
|
|
5258
|
+
2e3,
|
|
5259
|
+
2e3,
|
|
5260
|
+
2e3,
|
|
5261
|
+
2e3,
|
|
5262
|
+
2e3
|
|
5263
|
+
];
|
|
5229
5264
|
function splitFileIntoParts(file) {
|
|
5230
5265
|
const parts = [];
|
|
5231
5266
|
let start = 0;
|
|
@@ -6699,26 +6734,51 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6699
6734
|
if (abortSignal?.aborted) {
|
|
6700
6735
|
throw abortError;
|
|
6701
6736
|
}
|
|
6737
|
+
const handleRetryError = (err) => {
|
|
6738
|
+
if (abortSignal?.aborted) {
|
|
6739
|
+
throw abortError;
|
|
6740
|
+
}
|
|
6741
|
+
if (err instanceof CommentsApiError && err.status === 413) {
|
|
6742
|
+
throw err;
|
|
6743
|
+
}
|
|
6744
|
+
return false;
|
|
6745
|
+
};
|
|
6702
6746
|
if (attachment.size <= ATTACHMENT_PART_SIZE) {
|
|
6703
|
-
return
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6747
|
+
return autoRetry(
|
|
6748
|
+
() => fetchCommentsJson(
|
|
6749
|
+
`/attachments/${encodeURIComponent(attachment.id)}/upload/${encodeURIComponent(attachment.name)}`,
|
|
6750
|
+
{
|
|
6751
|
+
method: "PUT",
|
|
6752
|
+
body: attachment.file,
|
|
6753
|
+
signal: abortSignal
|
|
6754
|
+
},
|
|
6755
|
+
{
|
|
6756
|
+
fileSize: attachment.size
|
|
6757
|
+
}
|
|
6758
|
+
),
|
|
6759
|
+
RETRY_ATTEMPTS,
|
|
6760
|
+
RETRY_DELAYS,
|
|
6761
|
+
handleRetryError
|
|
6710
6762
|
);
|
|
6711
6763
|
} else {
|
|
6712
6764
|
let uploadId;
|
|
6713
6765
|
const uploadedParts = [];
|
|
6714
|
-
|
|
6715
|
-
|
|
6766
|
+
const createMultiPartUpload = await autoRetry(
|
|
6767
|
+
() => fetchCommentsJson(
|
|
6716
6768
|
`/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(attachment.name)}`,
|
|
6717
6769
|
{
|
|
6718
6770
|
method: "POST",
|
|
6719
6771
|
signal: abortSignal
|
|
6772
|
+
},
|
|
6773
|
+
{
|
|
6774
|
+
fileSize: attachment.size
|
|
6720
6775
|
}
|
|
6721
|
-
)
|
|
6776
|
+
),
|
|
6777
|
+
RETRY_ATTEMPTS,
|
|
6778
|
+
RETRY_DELAYS,
|
|
6779
|
+
handleRetryError
|
|
6780
|
+
);
|
|
6781
|
+
try {
|
|
6722
6782
|
uploadId = createMultiPartUpload.uploadId;
|
|
6723
6783
|
const parts = splitFileIntoParts(attachment.file);
|
|
6724
6784
|
if (abortSignal?.aborted) {
|
|
@@ -6729,13 +6789,18 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6729
6789
|
const uploadedPartsPromises = [];
|
|
6730
6790
|
for (const { part, partNumber } of parts2) {
|
|
6731
6791
|
uploadedPartsPromises.push(
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6792
|
+
autoRetry(
|
|
6793
|
+
() => fetchCommentsJson(
|
|
6794
|
+
`/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(createMultiPartUpload.uploadId)}/${encodeURIComponent(partNumber)}`,
|
|
6795
|
+
{
|
|
6796
|
+
method: "PUT",
|
|
6797
|
+
body: part,
|
|
6798
|
+
signal: abortSignal
|
|
6799
|
+
}
|
|
6800
|
+
),
|
|
6801
|
+
RETRY_ATTEMPTS,
|
|
6802
|
+
RETRY_DELAYS,
|
|
6803
|
+
handleRetryError
|
|
6739
6804
|
)
|
|
6740
6805
|
);
|
|
6741
6806
|
}
|
|
@@ -6760,13 +6825,16 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6760
6825
|
);
|
|
6761
6826
|
} catch (error3) {
|
|
6762
6827
|
if (uploadId && error3?.name && (error3.name === "AbortError" || error3.name === "TimeoutError")) {
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6828
|
+
try {
|
|
6829
|
+
await fetchCommentsApi(
|
|
6830
|
+
`/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(uploadId)}`,
|
|
6831
|
+
void 0,
|
|
6832
|
+
{
|
|
6833
|
+
method: "DELETE"
|
|
6834
|
+
}
|
|
6835
|
+
);
|
|
6836
|
+
} catch (error4) {
|
|
6837
|
+
}
|
|
6770
6838
|
}
|
|
6771
6839
|
throw error3;
|
|
6772
6840
|
}
|
|
@@ -8179,6 +8247,7 @@ export {
|
|
|
8179
8247
|
asPos,
|
|
8180
8248
|
assert,
|
|
8181
8249
|
assertNever,
|
|
8250
|
+
autoRetry,
|
|
8182
8251
|
b64decode,
|
|
8183
8252
|
chunk,
|
|
8184
8253
|
cloneLson,
|