@squiz/optimization-utils 4.4.0 → 4.5.0

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.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './types/class-utilities-types';
2
+ export * from './retries/Retries';
2
3
  export * from './object/getProperty';
3
4
  export * from './measurement/performance';
4
5
  export * from './data-structures/Result';
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./types/class-utilities-types"), exports);
18
+ __exportStar(require("./retries/Retries"), exports);
18
19
  __exportStar(require("./object/getProperty"), exports);
19
20
  __exportStar(require("./measurement/performance"), exports);
20
21
  __exportStar(require("./data-structures/Result"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA8C;AAC9C,uDAAqC;AACrC,4DAA0C;AAC1C,2DAAyC;AACzC,iEAA+C;AAC/C,mDAAiC;AACjC,iDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA8C;AAC9C,oDAAkC;AAClC,uDAAqC;AACrC,4DAA0C;AAC1C,2DAAyC;AACzC,iEAA+C;AAC/C,mDAAiC;AACjC,iDAA+B"}
@@ -0,0 +1,5 @@
1
+ export declare function Retry({ delay, retries, retryableErrors, }: {
2
+ retries: number;
3
+ delay: number;
4
+ retryableErrors: Array<new (...args: Array<any>) => Error>;
5
+ }): (_target: unknown, _propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Retry = Retry;
4
+ const promises_1 = require("timers/promises");
5
+ function Retry({ delay, retries, retryableErrors, }) {
6
+ return (_target, _propertyKey, descriptor) => {
7
+ const originalMethod = descriptor.value;
8
+ descriptor.value = async function (...args) {
9
+ let attempt = 0;
10
+ while (attempt <= retries) {
11
+ try {
12
+ return await originalMethod.apply(this, args);
13
+ }
14
+ catch (error) {
15
+ attempt++;
16
+ if (!retryableErrors.some((errType) => error instanceof errType)) {
17
+ throw error;
18
+ }
19
+ const isMaxRetriesReached = attempt > retries;
20
+ if (isMaxRetriesReached) {
21
+ throw error;
22
+ }
23
+ const _delay = delay * Math.pow(2, attempt - 1);
24
+ await (0, promises_1.setTimeout)(_delay);
25
+ }
26
+ }
27
+ };
28
+ return descriptor;
29
+ };
30
+ }
31
+ //# sourceMappingURL=Retries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Retries.js","sourceRoot":"","sources":["../../src/retries/Retries.ts"],"names":[],"mappings":";;AAEA,sBA+CC;AAjDD,8CAA6C;AAE7C,SAAgB,KAAK,CAAC,EACpB,KAAK,EACL,OAAO,EACP,eAAe,GAMhB;IACC,OAAO,CACL,OAAgB,EAChB,YAAoB,EACpB,UAA8B,EACV,EAAE;QACtB,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,KAAK,WACtB,GAAG,IAAoB;YAEvB,IAAI,OAAO,GAAG,CAAC,CAAC;YAEhB,OAAO,OAAO,IAAI,OAAO,EAAE,CAAC;gBAC1B,IAAI,CAAC;oBACH,OAAO,MAAM,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAChD,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,EAAE,CAAC;oBAEV,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,YAAY,OAAO,CAAC,EAAE,CAAC;wBACjE,MAAM,KAAK,CAAC;oBACd,CAAC;oBAED,MAAM,mBAAmB,GAAG,OAAO,GAAG,OAAO,CAAC;oBAE9C,IAAI,mBAAmB,EAAE,CAAC;wBACxB,MAAM,KAAK,CAAC;oBACd,CAAC;oBAED,MAAM,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC;oBAEhD,MAAM,IAAA,qBAAU,EAAC,MAAM,CAAC,CAAC;gBAC3B,CAAC;YACH,CAAC;QACH,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/optimization-utils",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",