@wix/builder-utils 1.21.3 → 1.21.5
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/bundles/debug/es/builder-utils.mjs +31 -1
- package/dist/bundles/debug/es/builder-utils.mjs.map +1 -1
- package/dist/bundles/debug/umd/builder-utils.js +30 -0
- package/dist/bundles/debug/umd/builder-utils.js.map +1 -1
- package/dist/bundles/es/builder-utils.mjs +215 -193
- package/dist/bundles/es/builder-utils.mjs.map +1 -1
- package/dist/bundles/umd/builder-utils.js +1 -1
- package/dist/bundles/umd/builder-utils.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/withRetry.d.ts +10 -0
- package/dist/withRetry.js +31 -0
- package/dist/withRetry.js.map +1 -0
- package/package.json +2 -3
- package/src/index.ts +2 -0
- package/src/withRetry.ts +43 -0
|
@@ -975,6 +975,34 @@
|
|
|
975
975
|
}
|
|
976
976
|
return isSignal(value) ? value.get() : value;
|
|
977
977
|
};
|
|
978
|
+
const retryStrategies = {
|
|
979
|
+
exponentialJitter: (initialDelayMs) => (attempt) => {
|
|
980
|
+
const base = initialDelayMs * Math.pow(2, attempt);
|
|
981
|
+
return base * (0.5 + Math.random() * 0.5);
|
|
982
|
+
}
|
|
983
|
+
};
|
|
984
|
+
function toError(error) {
|
|
985
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
986
|
+
}
|
|
987
|
+
async function withRetry(fn, options) {
|
|
988
|
+
const { maxRetries, getDelay, shouldRetry = () => true, onRetry } = options;
|
|
989
|
+
let lastError;
|
|
990
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
991
|
+
try {
|
|
992
|
+
return await fn();
|
|
993
|
+
} catch (error) {
|
|
994
|
+
lastError = toError(error);
|
|
995
|
+
if (attempt < maxRetries && shouldRetry(lastError, attempt)) {
|
|
996
|
+
const delayMs = getDelay(attempt);
|
|
997
|
+
onRetry?.(lastError, attempt, delayMs);
|
|
998
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
999
|
+
} else {
|
|
1000
|
+
break;
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
throw lastError ?? new Error(`Operation failed after ${maxRetries} retries`);
|
|
1005
|
+
}
|
|
978
1006
|
function getPageById(id, pageRegistry) {
|
|
979
1007
|
return pageRegistry[id] ?? null;
|
|
980
1008
|
}
|
|
@@ -1030,7 +1058,9 @@
|
|
|
1030
1058
|
exports2.getSignalValueDeep = getSignalValueDeep;
|
|
1031
1059
|
exports2.mergeProps = mergeProps;
|
|
1032
1060
|
exports2.removeElementProps = removeElementProps;
|
|
1061
|
+
exports2.retryStrategies = retryStrategies;
|
|
1033
1062
|
exports2.routeToDynamicPage = routeToDynamicPage;
|
|
1063
|
+
exports2.withRetry = withRetry;
|
|
1034
1064
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
1035
1065
|
});
|
|
1036
1066
|
//# sourceMappingURL=builder-utils.js.map
|