ag-common 0.0.30 → 0.0.31
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/dist/api/helpers/aws.d.ts +1 -0
- package/dist/api/helpers/aws.js +10 -0
- package/dist/api/helpers/dynamo.js +40 -10
- package/dist/api/helpers/index.d.ts +1 -0
- package/dist/api/helpers/index.js +1 -0
- package/dist/common/helpers/index.d.ts +1 -0
- package/dist/common/helpers/index.js +1 -0
- package/dist/common/helpers/sleep.d.ts +1 -0
- package/dist/common/helpers/sleep.js +7 -0
- package/dist/ui/helpers/callOpenApi.js +2 -2
- package/dist/ui/helpers/debounce.d.ts +0 -1
- package/dist/ui/helpers/debounce.js +1 -5
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const setAwsRegion: (region: string) => void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setAwsRegion = void 0;
|
|
4
|
+
const dynamo_1 = require("./dynamo");
|
|
5
|
+
const s3_1 = require("./s3");
|
|
6
|
+
const setAwsRegion = (region) => {
|
|
7
|
+
(0, dynamo_1.setDynamo)(region);
|
|
8
|
+
(0, s3_1.setS3)(region);
|
|
9
|
+
};
|
|
10
|
+
exports.setAwsRegion = setAwsRegion;
|
|
@@ -16,6 +16,7 @@ exports.wipeTable = exports.getDynamoTtl = exports.queryDynamo = exports.getItem
|
|
|
16
16
|
const aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
17
17
|
const log_1 = require("../../common/helpers/log");
|
|
18
18
|
const array_1 = require("../../common/helpers/array");
|
|
19
|
+
const sleep_1 = require("../../common/helpers/sleep");
|
|
19
20
|
// eslint-disable-next-line import/no-mutable-exports
|
|
20
21
|
exports.dynamoDb = new aws_sdk_1.default.DynamoDB.DocumentClient();
|
|
21
22
|
const setDynamo = (region) => {
|
|
@@ -40,6 +41,39 @@ const putDynamo = (item, tableName) => __awaiter(void 0, void 0, void 0, functio
|
|
|
40
41
|
return { data: item };
|
|
41
42
|
});
|
|
42
43
|
exports.putDynamo = putDynamo;
|
|
44
|
+
let batchWriteRaw = (req, debugMsg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
let count = 0;
|
|
46
|
+
let max = 5;
|
|
47
|
+
// eslint-disable-next-line no-constant-condition
|
|
48
|
+
while (true)
|
|
49
|
+
try {
|
|
50
|
+
const res = yield exports.dynamoDb
|
|
51
|
+
.batchWrite({
|
|
52
|
+
RequestItems: req,
|
|
53
|
+
})
|
|
54
|
+
.promise();
|
|
55
|
+
return res;
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
+
let es = e.toString();
|
|
60
|
+
if (es.indexOf('429') !== -1 ||
|
|
61
|
+
es.indexOf(' ProvisionedThroughputExceeded') !== -1) {
|
|
62
|
+
count += 1;
|
|
63
|
+
}
|
|
64
|
+
if (count >= max) {
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
67
|
+
let msg = `batch write throttled. retry ${count}/${max}`;
|
|
68
|
+
if (!debugMsg) {
|
|
69
|
+
(0, log_1.info)(msg);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
debugMsg(msg);
|
|
73
|
+
}
|
|
74
|
+
yield (0, sleep_1.sleep)(2000);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
43
77
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
44
78
|
const batchWrite = (tableName, itemsIn, breakOnError = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
79
|
var _a, _b;
|
|
@@ -50,16 +84,12 @@ const batchWrite = (tableName, itemsIn, breakOnError = false) => __awaiter(void
|
|
|
50
84
|
const { part, rest } = (0, array_1.take)(items, 25);
|
|
51
85
|
// eslint-disable-next-line no-param-reassign
|
|
52
86
|
items = rest;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
})),
|
|
60
|
-
},
|
|
61
|
-
})
|
|
62
|
-
.promise();
|
|
87
|
+
let req = {
|
|
88
|
+
[`${tableName}`]: part.map((item) => ({
|
|
89
|
+
PutRequest: { Item: item },
|
|
90
|
+
})),
|
|
91
|
+
};
|
|
92
|
+
let res = yield batchWriteRaw(req, (m) => (0, log_1.info)(`${m} remaining=${rest.length}`));
|
|
63
93
|
const newError = (_b = (_a = res.$response) === null || _a === void 0 ? void 0 : _a.error) !== null && _b !== void 0 ? _b : null;
|
|
64
94
|
if (newError) {
|
|
65
95
|
error.push(newError);
|
|
@@ -11,6 +11,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./api"), exports);
|
|
14
|
+
__exportStar(require("./aws"), exports);
|
|
14
15
|
__exportStar(require("./dynamo"), exports);
|
|
15
16
|
__exportStar(require("./dynamoInfra"), exports);
|
|
16
17
|
__exportStar(require("./openApiHelpers"), exports);
|
|
@@ -24,4 +24,5 @@ __exportStar(require("./math"), exports);
|
|
|
24
24
|
__exportStar(require("./object"), exports);
|
|
25
25
|
__exportStar(require("./random"), exports);
|
|
26
26
|
__exportStar(require("./secondsInNearest"), exports);
|
|
27
|
+
__exportStar(require("./sleep"), exports);
|
|
27
28
|
__exportStar(require("./string"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sleep: (ms: number) => Promise<void>;
|
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.callOpenApi = void 0;
|
|
13
13
|
const cookie_1 = require("./cookie");
|
|
14
|
-
const
|
|
14
|
+
const sleep_1 = require("../../common/helpers/sleep");
|
|
15
15
|
const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefaultApi, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
16
|
var _a, _b, _c, _d, _e, _f;
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -70,7 +70,7 @@ const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefa
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
// eslint-disable-next-line no-await-in-loop
|
|
73
|
-
yield (0,
|
|
73
|
+
yield (0, sleep_1.sleep)(2000);
|
|
74
74
|
}
|
|
75
75
|
return {
|
|
76
76
|
data,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.debounce = exports.
|
|
3
|
+
exports.debounce = exports.useDebounce = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
function useDebounce(value, delay) {
|
|
@@ -16,10 +16,6 @@ function useDebounce(value, delay) {
|
|
|
16
16
|
return debouncedValue;
|
|
17
17
|
}
|
|
18
18
|
exports.useDebounce = useDebounce;
|
|
19
|
-
const sleep = (ms) => {
|
|
20
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
21
|
-
};
|
|
22
|
-
exports.sleep = sleep;
|
|
23
19
|
const hashMap = {};
|
|
24
20
|
function debounce(callback, { key, time, }) {
|
|
25
21
|
clearTimeout(hashMap[key]);
|