@wix/builder-utils 1.21.4 → 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 -2
- package/src/index.ts +2 -0
- package/src/withRetry.ts +43 -0
|
@@ -971,6 +971,34 @@ const getSignalValueDeep = (target, path = "") => {
|
|
|
971
971
|
}
|
|
972
972
|
return isSignal(value) ? value.get() : value;
|
|
973
973
|
};
|
|
974
|
+
const retryStrategies = {
|
|
975
|
+
exponentialJitter: (initialDelayMs) => (attempt) => {
|
|
976
|
+
const base = initialDelayMs * Math.pow(2, attempt);
|
|
977
|
+
return base * (0.5 + Math.random() * 0.5);
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
function toError(error) {
|
|
981
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
982
|
+
}
|
|
983
|
+
async function withRetry(fn, options) {
|
|
984
|
+
const { maxRetries, getDelay, shouldRetry = () => true, onRetry } = options;
|
|
985
|
+
let lastError;
|
|
986
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
987
|
+
try {
|
|
988
|
+
return await fn();
|
|
989
|
+
} catch (error) {
|
|
990
|
+
lastError = toError(error);
|
|
991
|
+
if (attempt < maxRetries && shouldRetry(lastError, attempt)) {
|
|
992
|
+
const delayMs = getDelay(attempt);
|
|
993
|
+
onRetry?.(lastError, attempt, delayMs);
|
|
994
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
995
|
+
} else {
|
|
996
|
+
break;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
throw lastError ?? new Error(`Operation failed after ${maxRetries} retries`);
|
|
1001
|
+
}
|
|
974
1002
|
function getPageById(id, pageRegistry) {
|
|
975
1003
|
return pageRegistry[id] ?? null;
|
|
976
1004
|
}
|
|
@@ -1027,6 +1055,8 @@ export {
|
|
|
1027
1055
|
getSignalValueDeep,
|
|
1028
1056
|
mergeProps,
|
|
1029
1057
|
removeElementProps,
|
|
1030
|
-
|
|
1058
|
+
retryStrategies,
|
|
1059
|
+
routeToDynamicPage,
|
|
1060
|
+
withRetry
|
|
1031
1061
|
};
|
|
1032
1062
|
//# sourceMappingURL=builder-utils.mjs.map
|