@certik/skynet 0.20.0 → 0.20.2
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/CHANGELOG.md +10 -0
- package/availability.ts +26 -0
- package/dynamodb.ts +2 -2
- package/log.ts +10 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.20.2
|
|
4
|
+
|
|
5
|
+
- Make `options` in `withRetry` function optional
|
|
6
|
+
|
|
7
|
+
## 0.20.1
|
|
8
|
+
|
|
9
|
+
- Update dynamodb `scanWholeTable` types
|
|
10
|
+
- Add `logger` in log library
|
|
11
|
+
- Add `withRetry` in availability library
|
|
12
|
+
|
|
3
13
|
## 0.20.0
|
|
4
14
|
|
|
5
15
|
- Fix databricks with bun (extra step needed for projects using the lib):
|
package/availability.ts
CHANGED
|
@@ -46,3 +46,29 @@ export async function exponentialRetry<T>(
|
|
|
46
46
|
|
|
47
47
|
return result;
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
export function withRetry<F extends (...args: any[]) => any>(
|
|
52
|
+
func: F,
|
|
53
|
+
options?: { maxRetry?: number; initialDuration?: number; growFactor?: number },
|
|
54
|
+
) {
|
|
55
|
+
let retries = options?.maxRetry || 3;
|
|
56
|
+
let duration = options?.initialDuration || 500;
|
|
57
|
+
const growFactorFinal = options?.growFactor || 2;
|
|
58
|
+
|
|
59
|
+
return async (...args: Parameters<F>): Promise<ReturnType<F>> => {
|
|
60
|
+
do {
|
|
61
|
+
try {
|
|
62
|
+
return await func(...args);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
retries = retries - 1;
|
|
65
|
+
if (retries === 0) {
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
await wait(duration);
|
|
69
|
+
duration = duration * growFactorFinal;
|
|
70
|
+
}
|
|
71
|
+
} while (retries >= 0);
|
|
72
|
+
throw new Error("unreachable");
|
|
73
|
+
};
|
|
74
|
+
}
|
package/dynamodb.ts
CHANGED
|
@@ -56,7 +56,7 @@ function getDocClient(forceNew = false) {
|
|
|
56
56
|
return _docClient;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
async function scanWholeTable(options: ScanCommandInput) {
|
|
59
|
+
async function scanWholeTable<T>(options: ScanCommandInput) {
|
|
60
60
|
const dynamodb = getDocClient();
|
|
61
61
|
|
|
62
62
|
let items: ScanCommandOutput["Items"] = [];
|
|
@@ -82,7 +82,7 @@ async function scanWholeTable(options: ScanCommandInput) {
|
|
|
82
82
|
scannedCount += data.ScannedCount || 0;
|
|
83
83
|
|
|
84
84
|
return {
|
|
85
|
-
Items: items,
|
|
85
|
+
Items: items as T[],
|
|
86
86
|
Count: count,
|
|
87
87
|
ScannedCount: scannedCount,
|
|
88
88
|
};
|
package/log.ts
CHANGED
|
@@ -42,4 +42,13 @@ const inline = {
|
|
|
42
42
|
},
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
const logger = {
|
|
46
|
+
log: function (...args: unknown[]) {
|
|
47
|
+
console.log(`[${timestamp()}]`, ...args);
|
|
48
|
+
},
|
|
49
|
+
error: function (...args: unknown[]) {
|
|
50
|
+
console.error(`[${timestamp()}]`, ...args);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { print, getLine, inline, logger };
|