@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.
@@ -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