@reyaxyz/common 0.112.0 → 0.113.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/README.md CHANGED
@@ -6,5 +6,5 @@
6
6
 
7
7
  | Statements | Branches | Functions | Lines |
8
8
  | --------------------------- | ----------------------- | ------------------------- | ----------------- |
9
- | ![Statements](https://img.shields.io/badge/statements-13.69%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-14.66%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-9.75%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-14.05%25-red.svg?style=flat) |
9
+ | ![Statements](https://img.shields.io/badge/statements-13.69%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-14.56%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-9.75%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-14.05%25-red.svg?style=flat) |
10
10
 
@@ -1,2 +1,2 @@
1
- export declare const exponentialBackoff: <T = never>(query: () => Promise<T>, attempts?: number, factor?: number) => Promise<T>;
1
+ export declare const exponentialBackoff: <T = never>(query: () => Promise<T>, attempts?: number, factor?: number, waitingTimeStart?: number) => Promise<T>;
2
2
  //# sourceMappingURL=retry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"retry.d.ts","sourceRoot":"/","sources":["utils/retry.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,kBAAkB,wFAuB9B,CAAC"}
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"/","sources":["utils/retry.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,kBAAkB,mHAwB9B,CAAC"}
@@ -47,19 +47,20 @@ function getRandomNumber(max) {
47
47
  }
48
48
  // It retries a call for a few times while waiting an exponential time before each new attempt.
49
49
  // You pass the query and the number of attempts you want to use and it performs as follows:
50
- // 1. Initiates the waiting time to 1s
50
+ // 1. Initiates the waiting time to waitingTimeStart
51
51
  // 2. Tries to fetch the data
52
52
  // 3.1. If it succeeds, it returns the data
53
53
  // 3.2. If it fails, it waits, it doubles the waiting time and go to point 2. if the number of attemps is not reached
54
- var exponentialBackoff = function (query, attempts, factor) {
54
+ var exponentialBackoff = function (query, attempts, factor, waitingTimeStart) {
55
55
  if (attempts === void 0) { attempts = 5; }
56
56
  if (factor === void 0) { factor = 2; }
57
+ if (waitingTimeStart === void 0) { waitingTimeStart = 1000; }
57
58
  return __awaiter(void 0, void 0, void 0, function () {
58
59
  var waitingTime, attempt, data, error_1;
59
60
  return __generator(this, function (_a) {
60
61
  switch (_a.label) {
61
62
  case 0:
62
- waitingTime = 1000;
63
+ waitingTime = waitingTimeStart;
63
64
  attempt = 0;
64
65
  _a.label = 1;
65
66
  case 1:
@@ -1 +1 @@
1
- {"version":3,"file":"retry.js","sourceRoot":"/","sources":["utils/retry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA2C;AAC3C,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,IAAK,OAAA,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,EAAvB,CAAuB,CAAC,CAAC;AAC3D,CAAC;AAED,gDAAgD;AAChD,SAAS,eAAe,CAAC,GAAW;IAClC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;AACzC,CAAC;AAED,+FAA+F;AAC/F,4FAA4F;AAC5F,sCAAsC;AACtC,6BAA6B;AAC7B,2CAA2C;AAC3C,qHAAqH;AAC9G,IAAM,kBAAkB,GAAG,UAChC,KAAuB,EACvB,QAAY,EACZ,MAAU;IADV,yBAAA,EAAA,YAAY;IACZ,uBAAA,EAAA,UAAU;;;;;;oBAEN,WAAW,GAAG,IAAI,CAAC;oBAEd,OAAO,GAAG,CAAC;;;yBAAE,CAAA,OAAO,GAAG,QAAQ,CAAA;;;;oBAEvB,qBAAM,KAAK,EAAE,EAAA;;oBAApB,IAAI,GAAG,SAAa;oBAE1B,sBAAO,IAAI,EAAC;;;oBAEZ,IAAI,OAAO,GAAG,CAAC,KAAK,QAAQ,EAAE,CAAC;wBAC7B,MAAM,OAAK,CAAC;oBACd,CAAC;;wBAGH,qBAAM,KAAK,CAAC,WAAW,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,EAAA;;oBAA/C,SAA+C,CAAC;oBAChD,WAAW,IAAI,MAAM,CAAC;;;oBAZkB,OAAO,IAAI,CAAC,CAAA;;wBAetD,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;;;;CACnD,CAAC;AAvBW,QAAA,kBAAkB,sBAuB7B","sourcesContent":["// It introduces a delay of ms milliseconds\nfunction delay(ms: number): Promise<unknown> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n// It returns a random number between [0, max-1]\nfunction getRandomNumber(max: number): number {\n return Math.floor(Math.random() * max);\n}\n\n// It retries a call for a few times while waiting an exponential time before each new attempt.\n// You pass the query and the number of attempts you want to use and it performs as follows:\n// 1. Initiates the waiting time to 1s\n// 2. Tries to fetch the data\n// 3.1. If it succeeds, it returns the data\n// 3.2. If it fails, it waits, it doubles the waiting time and go to point 2. if the number of attemps is not reached\nexport const exponentialBackoff = async <T = never>(\n query: () => Promise<T>,\n attempts = 5,\n factor = 2,\n): Promise<T> => {\n let waitingTime = 1000;\n\n for (let attempt = 0; attempt < attempts; attempt += 1) {\n try {\n const data = await query();\n\n return data;\n } catch (error) {\n if (attempt + 1 === attempts) {\n throw error;\n }\n }\n\n await delay(waitingTime + getRandomNumber(100));\n waitingTime *= factor;\n }\n\n throw new Error('Retry loop failed unexpectedly');\n};\n"]}
1
+ {"version":3,"file":"retry.js","sourceRoot":"/","sources":["utils/retry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA2C;AAC3C,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,IAAK,OAAA,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,EAAvB,CAAuB,CAAC,CAAC;AAC3D,CAAC;AAED,gDAAgD;AAChD,SAAS,eAAe,CAAC,GAAW;IAClC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;AACzC,CAAC;AAED,+FAA+F;AAC/F,4FAA4F;AAC5F,oDAAoD;AACpD,6BAA6B;AAC7B,2CAA2C;AAC3C,qHAAqH;AAC9G,IAAM,kBAAkB,GAAG,UAChC,KAAuB,EACvB,QAAY,EACZ,MAAU,EACV,gBAAuB;IAFvB,yBAAA,EAAA,YAAY;IACZ,uBAAA,EAAA,UAAU;IACV,iCAAA,EAAA,uBAAuB;;;;;;oBAEnB,WAAW,GAAG,gBAAgB,CAAC;oBAE1B,OAAO,GAAG,CAAC;;;yBAAE,CAAA,OAAO,GAAG,QAAQ,CAAA;;;;oBAEvB,qBAAM,KAAK,EAAE,EAAA;;oBAApB,IAAI,GAAG,SAAa;oBAE1B,sBAAO,IAAI,EAAC;;;oBAEZ,IAAI,OAAO,GAAG,CAAC,KAAK,QAAQ,EAAE,CAAC;wBAC7B,MAAM,OAAK,CAAC;oBACd,CAAC;;wBAGH,qBAAM,KAAK,CAAC,WAAW,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,EAAA;;oBAA/C,SAA+C,CAAC;oBAChD,WAAW,IAAI,MAAM,CAAC;;;oBAZkB,OAAO,IAAI,CAAC,CAAA;;wBAetD,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;;;;CACnD,CAAC;AAxBW,QAAA,kBAAkB,sBAwB7B","sourcesContent":["// It introduces a delay of ms milliseconds\nfunction delay(ms: number): Promise<unknown> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n// It returns a random number between [0, max-1]\nfunction getRandomNumber(max: number): number {\n return Math.floor(Math.random() * max);\n}\n\n// It retries a call for a few times while waiting an exponential time before each new attempt.\n// You pass the query and the number of attempts you want to use and it performs as follows:\n// 1. Initiates the waiting time to waitingTimeStart\n// 2. Tries to fetch the data\n// 3.1. If it succeeds, it returns the data\n// 3.2. If it fails, it waits, it doubles the waiting time and go to point 2. if the number of attemps is not reached\nexport const exponentialBackoff = async <T = never>(\n query: () => Promise<T>,\n attempts = 5,\n factor = 2,\n waitingTimeStart = 1000,\n): Promise<T> => {\n let waitingTime = waitingTimeStart;\n\n for (let attempt = 0; attempt < attempts; attempt += 1) {\n try {\n const data = await query();\n\n return data;\n } catch (error) {\n if (attempt + 1 === attempts) {\n throw error;\n }\n }\n\n await delay(waitingTime + getRandomNumber(100));\n waitingTime *= factor;\n }\n\n throw new Error('Retry loop failed unexpectedly');\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/common",
3
- "version": "0.112.0",
3
+ "version": "0.113.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -42,5 +42,5 @@
42
42
  "generate:coverage-badges": "npx istanbul-badges-readme --silent"
43
43
  },
44
44
  "packageManager": "pnpm@8.3.1",
45
- "gitHead": "e24a305d805dc3a4d38a124538e5a7285aa9344e"
45
+ "gitHead": "21d078afc658b56f6bfa4fd352a3bf7016ddb369"
46
46
  }
@@ -10,7 +10,7 @@ function getRandomNumber(max: number): number {
10
10
 
11
11
  // It retries a call for a few times while waiting an exponential time before each new attempt.
12
12
  // You pass the query and the number of attempts you want to use and it performs as follows:
13
- // 1. Initiates the waiting time to 1s
13
+ // 1. Initiates the waiting time to waitingTimeStart
14
14
  // 2. Tries to fetch the data
15
15
  // 3.1. If it succeeds, it returns the data
16
16
  // 3.2. If it fails, it waits, it doubles the waiting time and go to point 2. if the number of attemps is not reached
@@ -18,8 +18,9 @@ export const exponentialBackoff = async <T = never>(
18
18
  query: () => Promise<T>,
19
19
  attempts = 5,
20
20
  factor = 2,
21
+ waitingTimeStart = 1000,
21
22
  ): Promise<T> => {
22
- let waitingTime = 1000;
23
+ let waitingTime = waitingTimeStart;
23
24
 
24
25
  for (let attempt = 0; attempt < attempts; attempt += 1) {
25
26
  try {