@layerzerolabs/devtools
Advanced tools
Comparing version 0.3.21 to 0.3.22
@@ -347,3 +347,3 @@ import { EndpointId } from '@layerzerolabs/lz-definitions'; | ||
*/ | ||
enabled?: boolean; | ||
enabled: boolean; | ||
/** | ||
@@ -360,3 +360,3 @@ * The maximum delay, in milliseconds, between two consecutive attempts. | ||
*/ | ||
numAttempts?: number; | ||
numAttempts: number; | ||
/** | ||
@@ -373,4 +373,23 @@ * Callback called on every failed attempt. | ||
*/ | ||
onRetry?: OnRetry<TInstance>; | ||
onRetry: OnRetry<TInstance>; | ||
} | ||
interface TAsyncRetriable { | ||
<TArgs extends unknown[], TResult>(overrides?: Partial<RetriableConfig>): (target: unknown, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: TArgs) => Promise<TResult>>) => TypedPropertyDescriptor<(...args: TArgs) => Promise<TResult>>; | ||
/** | ||
* The default config used by all Asyncretriable decorators. | ||
* | ||
* This config can be updated at runtime by setting its properties: | ||
* | ||
* ``` | ||
* AsyncRetriable.config.numAttempts = 10 | ||
* ``` | ||
*/ | ||
config: RetriableConfig; | ||
/** | ||
* Resets the config to its default state | ||
* | ||
* @returns {void} | ||
*/ | ||
reset: () => void; | ||
} | ||
/** | ||
@@ -381,3 +400,3 @@ * Helper function that creates a default debug logger for the `onRetry` | ||
declare const createDefaultRetryHandler: (loggerName?: string) => OnRetry<unknown>; | ||
declare const AsyncRetriable: ({ enabled, maxDelay, numAttempts, onRetry, }?: RetriableConfig) => <TArgs extends unknown[], TResult>(target: unknown, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: TArgs) => Promise<TResult>>) => TypedPropertyDescriptor<(...args: TArgs) => Promise<TResult>>; | ||
declare const AsyncRetriable: TAsyncRetriable; | ||
@@ -384,0 +403,0 @@ /** |
@@ -485,12 +485,4 @@ 'use strict'; | ||
}; | ||
var AsyncRetriable = ({ | ||
enabled = true, | ||
maxDelay, | ||
numAttempts = 3, | ||
onRetry = createDefaultRetryHandler() | ||
} = {}) => { | ||
var AsyncRetriable = (overrides = {}) => { | ||
return function AsyncRetriableDecorator(target, propertyKey, descriptor) { | ||
if (!enabled) { | ||
return descriptor; | ||
} | ||
const originalMethod = descriptor.value; | ||
@@ -502,6 +494,15 @@ assert__default.default( | ||
const handleRetry = (args) => (error, attempt) => { | ||
var _a4; | ||
return (_a4 = onRetry == null ? void 0 : onRetry(attempt, numAttempts, error, target, propertyKey, args)) != null ? _a4 : true; | ||
var _a4, _b, _c; | ||
const numAttempts = (_a4 = overrides.numAttempts) != null ? _a4 : AsyncRetriable.config.numAttempts; | ||
const onRetry = (_b = overrides.onRetry) != null ? _b : AsyncRetriable.config.onRetry; | ||
return (_c = onRetry(attempt, numAttempts, error, target, propertyKey, args)) != null ? _c : true; | ||
}; | ||
const retriedMethod = function(...args) { | ||
var _a4, _b, _c; | ||
const enabled = (_a4 = overrides.enabled) != null ? _a4 : AsyncRetriable.config.enabled; | ||
if (!enabled) { | ||
return originalMethod.apply(this, args); | ||
} | ||
const maxDelay = (_b = overrides.numAttempts) != null ? _b : AsyncRetriable.config.maxDelay; | ||
const numAttempts = (_c = overrides.numAttempts) != null ? _c : AsyncRetriable.config.numAttempts; | ||
return exponentialBackoff.backOff(() => originalMethod.apply(this, args), { | ||
@@ -519,2 +520,11 @@ // A typical problem in our case is 429 Too many requests | ||
}; | ||
var DEFAULT_CONFIG = { | ||
enabled: true, | ||
numAttempts: 3, | ||
onRetry: createDefaultRetryHandler() | ||
}; | ||
AsyncRetriable.config = { ...DEFAULT_CONFIG }; | ||
AsyncRetriable.reset = () => { | ||
AsyncRetriable.config = { ...DEFAULT_CONFIG }; | ||
}; | ||
@@ -521,0 +531,0 @@ // src/common/strings.ts |
{ | ||
"name": "@layerzerolabs/devtools", | ||
"version": "0.3.21", | ||
"version": "0.3.22", | ||
"description": "Core utilities for working with LayerZero on-chain infrastructure", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
288381
2338