Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

ts-retry

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-retry - npm Package Compare versions

Comparing version
5.0.1
to
6.0.0
+9
lib/cjs/retry/utils/erros/abortError.d.ts
export declare class AbortError extends Error {
private error;
private currentTry;
constructor(error: Error, currentTry: number);
abortError: boolean;
getError(): Error;
getCurrentTry(): number;
}
export declare function isAbortError(error: unknown): error is AbortError;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isAbortError = exports.AbortError = void 0;
class AbortError extends Error {
constructor(error, currentTry) {
super("function call aborted due to an error");
this.error = error;
this.currentTry = currentTry;
this.abortError = true;
}
getError() {
return this.error;
}
getCurrentTry() {
return this.currentTry;
}
}
exports.AbortError = AbortError;
function isAbortError(error) {
return error.abortError === true;
}
exports.isAbortError = isAbortError;
export declare class TooManyTries<RETURN_TYPE> extends Error {
private lastResult;
constructor(lastResult?: RETURN_TYPE | undefined);
tooManyTries: boolean;
getLastResult(): RETURN_TYPE | undefined;
}
export declare function isTooManyTries(error: unknown): error is TooManyTries<any>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isTooManyTries = exports.TooManyTries = void 0;
class TooManyTries extends Error {
constructor(lastResult = undefined) {
super("function did not complete within allowed number of attempts");
this.lastResult = lastResult;
this.tooManyTries = true;
}
getLastResult() {
return this.lastResult;
}
}
exports.TooManyTries = TooManyTries;
function isTooManyTries(error) {
return error.tooManyTries === true;
}
exports.isTooManyTries = isTooManyTries;
export declare class TooManyTries<RETURN_TYPE> extends Error {
private lastResult;
constructor(lastResult?: RETURN_TYPE | undefined);
tooManyTries: boolean;
getLastResult(): RETURN_TYPE | undefined;
}
export declare function isTooManyTries(error: unknown): error is TooManyTries<any>;
export class TooManyTries extends Error {
constructor(lastResult = undefined) {
super("function did not complete within allowed number of attempts");
this.lastResult = lastResult;
this.tooManyTries = true;
}
getLastResult() {
return this.lastResult;
}
}
export function isTooManyTries(error) {
return error.tooManyTries === true;
}
+17
-0

@@ -0,1 +1,18 @@

# 6.0.0
onError function may now return boolean:
- when returning nothing (behavior until 5.x): retries continue
- when returnin true, retries continue
- when returning flase, retries stops and an AbortError is thrown
The behavior of previuos release is preserve. If you don't want to use this functionality you do not need do
do any change in tour code
AbortError:
An error thrown when reties are aborted due to an exception
getError return the last error
getCurrentTry the aborte try
# 5.0.1

@@ -2,0 +19,0 @@

+2
-2
export type { RetryOptions } from "./options";
export { getDefaultRetryOptions, setDefaultRetryOptions } from "./options";
export { retry, retryAsync } from "./retry";
export type { TooManyTries } from "./tooManyTries";
export { isTooManyTries } from "./tooManyTries";
export type { TooManyTries } from "./utils/erros/tooManyTries";
export { isTooManyTries } from "./utils/erros/tooManyTries";
export type { RetryUtilsOptions } from "./utils";
export { retryAsyncUntilDefined, retryAsyncUntilDefinedDecorator, retryAsyncUntilTruthy, retryAsyncUntilTruthyDecorator, retryUntilDefined, retryUntilDefinedDecorator, retryUntilTruthy, retryUntilTruthyDecorator, retryAsyncUntilResponse, retryAsyncUntilResponseDecorator, createExponetialDelay, createMutiplicableDelay, createRandomDelay, retryAsyncDecorator, retryDecorator, } from "./utils";

@@ -10,3 +10,3 @@ "use strict";

Object.defineProperty(exports, "retryAsync", { enumerable: true, get: function () { return retry_1.retryAsync; } });
var tooManyTries_1 = require("./tooManyTries");
var tooManyTries_1 = require("./utils/erros/tooManyTries");
Object.defineProperty(exports, "isTooManyTries", { enumerable: true, get: function () { return tooManyTries_1.isTooManyTries; } });

@@ -13,0 +13,0 @@ var utils_1 = require("./utils");

@@ -13,3 +13,3 @@ export type UNTIL<RETURN_TYPE> = (result: RETURN_TYPE) => boolean;

until?: UNTIL<RETURN_TYPE> | null;
onError?: (err: Error, currentTry: number) => void;
onError?: (err: Error, currentTry: number) => boolean | undefined;
onMaxRetryFunc?: (err: Error, currentTry: number) => void;

@@ -16,0 +16,0 @@ onSuccessFunc?: (result: RETURN_TYPE, currentTry: number) => void;

@@ -10,4 +10,4 @@ import { DELAY, RetryOptions, UNTIL } from "./options";

onSuccessFunc?: (result: RETURN_TYPE, currentTry: number) => void;
onError?: (err: Error, currentTry: number) => void;
onError?: (err: Error, currentTry: number) => boolean | undefined;
}
export declare function getRetryParameters<RETURN_TYPE>(currentTry: number, retryOptions?: RetryOptions<RETURN_TYPE>): Readonly<RetryParameters<RETURN_TYPE>>;

@@ -16,3 +16,4 @@ "use strict";

const parameters_1 = require("./parameters");
const tooManyTries_1 = require("./tooManyTries");
const abortError_1 = require("./utils/erros/abortError");
const tooManyTries_1 = require("./utils/erros/tooManyTries");
function retry(fn, retryOptions) {

@@ -33,2 +34,3 @@ return __awaiter(this, void 0, void 0, function* () {

function actualRetry(fn, retryParameters) {
var _a;
return __awaiter(this, void 0, void 0, function* () {

@@ -55,4 +57,5 @@ const canRecall = retryParameters.currentTry < retryParameters.maxTry;

if (!(0, tooManyTries_1.isTooManyTries)(err) && canRecall) {
if (retryParameters.onError) {
retryParameters.onError(err, retryParameters.currentTry);
const canRecall = (_a = retryParameters.onError) === null || _a === void 0 ? void 0 : _a.call(retryParameters, err, retryParameters.currentTry);
if (canRecall === false) {
throw new abortError_1.AbortError(err, retryParameters.currentTry);
}

@@ -59,0 +62,0 @@ return yield recall(fn, retryParameters);

export type { RetryOptions } from "./options";
export { getDefaultRetryOptions, setDefaultRetryOptions } from "./options";
export { retry, retryAsync } from "./retry";
export type { TooManyTries } from "./tooManyTries";
export { isTooManyTries } from "./tooManyTries";
export type { TooManyTries } from "./utils/erros/tooManyTries";
export { isTooManyTries } from "./utils/erros/tooManyTries";
export type { RetryUtilsOptions } from "./utils";
export { retryAsyncUntilDefined, retryAsyncUntilDefinedDecorator, retryAsyncUntilTruthy, retryAsyncUntilTruthyDecorator, retryUntilDefined, retryUntilDefinedDecorator, retryUntilTruthy, retryUntilTruthyDecorator, retryAsyncUntilResponse, retryAsyncUntilResponseDecorator, createExponetialDelay, createMutiplicableDelay, createRandomDelay, retryAsyncDecorator, retryDecorator, } from "./utils";
export { getDefaultRetryOptions, setDefaultRetryOptions } from "./options";
export { retry, retryAsync } from "./retry";
export { isTooManyTries } from "./tooManyTries";
export { isTooManyTries } from "./utils/erros/tooManyTries";
export { retryAsyncUntilDefined, retryAsyncUntilDefinedDecorator, retryAsyncUntilTruthy, retryAsyncUntilTruthyDecorator, retryUntilDefined, retryUntilDefinedDecorator, retryUntilTruthy, retryUntilTruthyDecorator, retryAsyncUntilResponse, retryAsyncUntilResponseDecorator, createExponetialDelay, createMutiplicableDelay, createRandomDelay, retryAsyncDecorator, retryDecorator, } from "./utils";

@@ -13,3 +13,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import { getRetryParameters } from "./parameters";
import { isTooManyTries, TooManyTries } from "./tooManyTries";
import { isTooManyTries, TooManyTries } from "./utils/erros/tooManyTries";
export function retry(fn, retryOptions) {

@@ -16,0 +16,0 @@ return __awaiter(this, void 0, void 0, function* () {

{
"name": "ts-retry",
"version": "5.0.1",
"version": "6.0.0",
"main": "lib/cjs/index.js",

@@ -5,0 +5,0 @@ "module": "lib/esm/index.js",

export declare class TooManyTries<RETURN_TYPE> extends Error {
private lastResult;
constructor(lastResult?: RETURN_TYPE | undefined);
tooManyTries: boolean;
getLastResult(): RETURN_TYPE | undefined;
}
export declare function isTooManyTries(error: unknown): error is TooManyTries<any>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isTooManyTries = exports.TooManyTries = void 0;
class TooManyTries extends Error {
constructor(lastResult = undefined) {
super("function did not complete within allowed number of attempts");
this.lastResult = lastResult;
this.tooManyTries = true;
}
getLastResult() {
return this.lastResult;
}
}
exports.TooManyTries = TooManyTries;
function isTooManyTries(error) {
return error.tooManyTries === true;
}
exports.isTooManyTries = isTooManyTries;
export declare class TooManyTries<RETURN_TYPE> extends Error {
private lastResult;
constructor(lastResult?: RETURN_TYPE | undefined);
tooManyTries: boolean;
getLastResult(): RETURN_TYPE | undefined;
}
export declare function isTooManyTries(error: unknown): error is TooManyTries<any>;
export class TooManyTries extends Error {
constructor(lastResult = undefined) {
super("function did not complete within allowed number of attempts");
this.lastResult = lastResult;
this.tooManyTries = true;
}
getLastResult() {
return this.lastResult;
}
}
export function isTooManyTries(error) {
return error.tooManyTries === true;
}