@augment-vir/common 21.4.0 → 21.5.1

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.callAsynchronously = exports.wrapPromiseInTimeout = exports.PromiseTimeoutError = exports.isPromiseLike = void 0;
3
+ exports.executeWithRetries = exports.callAsynchronously = exports.wrapPromiseInTimeout = exports.PromiseTimeoutError = exports.isPromiseLike = void 0;
4
4
  const typed_has_property_1 = require("../object/typed-has-property");
5
5
  function isPromiseLike(input) {
6
6
  if ((0, typed_has_property_1.typedHasProperty)(input, 'then') && typeof input.then === 'function') {
@@ -48,3 +48,17 @@ async function callAsynchronously(callback) {
48
48
  return await Promise.resolve().then(() => callback());
49
49
  }
50
50
  exports.callAsynchronously = callAsynchronously;
51
+ async function executeWithRetries(retryCount, callback) {
52
+ let currentRetry = 0;
53
+ while (currentRetry < retryCount) {
54
+ try {
55
+ const result = await callback();
56
+ return result;
57
+ }
58
+ catch (error) {
59
+ currentRetry++;
60
+ }
61
+ }
62
+ throw new Error('Retry max reached.');
63
+ }
64
+ exports.executeWithRetries = executeWithRetries;
@@ -41,3 +41,16 @@ export function wrapPromiseInTimeout(durationMs, originalPromise) {
41
41
  export async function callAsynchronously(callback) {
42
42
  return await Promise.resolve().then(() => callback());
43
43
  }
44
+ export async function executeWithRetries(retryCount, callback) {
45
+ let currentRetry = 0;
46
+ while (currentRetry < retryCount) {
47
+ try {
48
+ const result = await callback();
49
+ return result;
50
+ }
51
+ catch (error) {
52
+ currentRetry++;
53
+ }
54
+ }
55
+ throw new Error('Retry max reached.');
56
+ }
@@ -1,7 +1,7 @@
1
1
  import { ArrayElement } from '../type';
2
2
  import { PropertyValueType } from './object';
3
3
  import { UnionToIntersection } from './old-union-to-intersection';
4
- export type NestedSequentialKeys<ObjectGeneric extends object> = NonNullable<ObjectGeneric> extends ReadonlyArray<any> ? NestedSequentialKeys<Extract<NonNullable<ObjectGeneric>[number], object>> : PropertyValueType<{
4
+ export type NestedSequentialKeys<ObjectGeneric extends object> = NonNullable<ObjectGeneric> extends ReadonlyArray<any> ? Extract<NonNullable<ObjectGeneric>[number], object> extends never ? [number] : NestedSequentialKeys<Extract<NonNullable<ObjectGeneric>[number], object>> : PropertyValueType<{
5
5
  [Prop in keyof ObjectGeneric]: NonNullable<ObjectGeneric[Prop]> extends object ? Readonly<[
6
6
  Prop,
7
7
  ...(NestedSequentialKeys<NonNullable<ObjectGeneric[Prop]>> | [])
@@ -12,3 +12,4 @@ export declare function wrapPromiseInTimeout<PromiseValueType>(durationMs: numbe
12
12
  * function was originally synchronous.
13
13
  */
14
14
  export declare function callAsynchronously<T>(callback: () => MaybePromise<T>): Promise<T>;
15
+ export declare function executeWithRetries<T>(retryCount: number, callback: () => T): Promise<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "21.4.0",
3
+ "version": "21.5.1",
4
4
  "homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
5
5
  "bugs": {
6
6
  "url": "https://github.com/electrovir/augment-vir/issues"