Skip to content

Commit 5376d88

Browse files
committed
fixed known issues, updated tsconfig and package.json
1 parent 3621db1 commit 5376d88

File tree

5 files changed

+37
-33
lines changed

5 files changed

+37
-33
lines changed

index.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"name": "retry.js",
2+
"name": "must-retry.js",
33
"version": "1.0.0",
4-
"description": "A simple but powerfull library for your retrying operations.",
4+
"description": "A simple but powerful library for your retrying operations.",
55
"main": "dist/index.js",
6-
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
8-
"build": "tsc"
9-
},
106
"types": "dist/index.d.ts",
117
"files": [
128
"/dist"
139
],
10+
"scripts": {
11+
"test": "echo \"Error: no test specified\" && exit 1",
12+
"build": "tsc"
13+
},
1414
"keywords": [
1515
"retry.js",
1616
"retry",

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export {
2+
retryOperation,
3+
retryAsyncOperation,
4+
RetryAsyncOperation,
5+
RetryOperation,
6+
} from "./lib/retryOperation";

lib/retryOperation.ts renamed to src/lib/retryOperation.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface IRetryOperation {
1+
interface RetryOperation {
22
retryCount: number | "infinite";
33
retryDelay: number;
44
retryCallback: (payload?: any) => any;
@@ -8,6 +8,12 @@ export interface IRetryOperation {
88
incrementalDelayFactor?: number; // Optional factor to increase the delay
99
}
1010

11+
interface RetryAsyncOperationExtended extends RetryOperation {
12+
retryAsyncCallback: () => Promise<void>;
13+
}
14+
15+
type RetryAsyncOperation = Omit<RetryAsyncOperationExtended, "retryCallback">;
16+
1117
const sleep = (delay: number) => {
1218
return new Promise((resolve) => setTimeout(resolve, delay));
1319
};
@@ -20,7 +26,7 @@ async function retryOperation({
2026
onSuccessCallback,
2127
afterLastAttemptErrorCallback,
2228
incrementalDelayFactor = 1, // Default factor is 1 (no increment)
23-
}: IRetryOperation) {
29+
}: RetryOperation) {
2430
let noOfRetries = 0;
2531
let lastError: any = null;
2632
let currentDelay = retryDelay;
@@ -39,7 +45,7 @@ async function retryOperation({
3945
return;
4046
} catch (error) {
4147
lastError = error;
42-
onErrorCallback(error);
48+
onErrorCallback(error as Error);
4349
currentDelay *= incrementalDelayFactor; // Increase the delay
4450
}
4551
}
@@ -48,11 +54,6 @@ async function retryOperation({
4854
afterLastAttemptErrorCallback(lastError);
4955
}
5056
}
51-
interface TRetryAsyncOperationF extends IRetryOperation {
52-
retryAsyncCallback: () => Promise<void>;
53-
}
54-
55-
type TRetryAsyncOperation = Omit<TRetryAsyncOperationF, "retryCallback">;
5657

5758
async function retryAsyncOperation({
5859
retryCount,
@@ -62,7 +63,7 @@ async function retryAsyncOperation({
6263
onSuccessCallback,
6364
afterLastAttemptErrorCallback,
6465
incrementalDelayFactor = 1, // Default factor is 1 (no increment)
65-
}: TRetryAsyncOperation) {
66+
}: RetryAsyncOperation) {
6667
let noOfRetries = 0;
6768
let lastError: any = null;
6869
let currentDelay = retryDelay;
@@ -81,7 +82,7 @@ async function retryAsyncOperation({
8182
return;
8283
} catch (error) {
8384
lastError = error;
84-
onErrorCallback(error);
85+
onErrorCallback(error as Error);
8586
currentDelay *= incrementalDelayFactor; // Increase the delay
8687
}
8788
}
@@ -91,4 +92,9 @@ async function retryAsyncOperation({
9192
}
9293
}
9394

94-
export { retryOperation, retryAsyncOperation };
95+
export {
96+
retryOperation,
97+
retryAsyncOperation,
98+
RetryOperation,
99+
RetryAsyncOperation,
100+
};

tsconfig.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"compilerOptions": {
3-
/* Visit https://aka.ms/tsconfig to read more about this file */
4-
3+
"target": "ES6",
54
"module": "commonjs",
6-
"target": "ES2016",
7-
"declaration": true,
8-
"moduleDetection": "force",
9-
"outDir": "./dist"
10-
}
5+
"sourceMap": true,
6+
"outDir": "./dist",
7+
"noImplicitAny": true,
8+
"declaration": true
9+
},
10+
"include": ["src/**/*"],
11+
"exclude": ["node_modules"]
1112
}

0 commit comments

Comments
 (0)