ag-common 0.0.27 → 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 +2 -0
- package/dist/api/helpers/index.js +2 -0
- package/dist/api/helpers/s3.d.ts +15 -0
- package/dist/api/helpers/s3.js +37 -0
- package/dist/common/helpers/generator.d.ts +1 -0
- package/dist/common/helpers/generator.js +26 -0
- package/dist/common/helpers/index.d.ts +2 -0
- package/dist/common/helpers/index.js +2 -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 +7 -13
- 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,8 +11,10 @@ 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);
|
|
18
|
+
__exportStar(require("./s3"), exports);
|
|
17
19
|
__exportStar(require("./validateOpenApi"), exports);
|
|
18
20
|
__exportStar(require("./validations"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Blob } from 'aws-sdk/lib/dynamodb/document_client';
|
|
2
|
+
import AWS from 'aws-sdk';
|
|
3
|
+
export declare const setS3: (region: string) => void;
|
|
4
|
+
export declare const getS3Object: ({ fileurl, }: {
|
|
5
|
+
fileurl: {
|
|
6
|
+
Bucket: string;
|
|
7
|
+
Key: string;
|
|
8
|
+
};
|
|
9
|
+
}) => Promise<import("aws-sdk/lib/request").PromiseResult<AWS.S3.GetObjectOutput, AWS.AWSError>>;
|
|
10
|
+
export declare const putS3Object: ({ Body, Bucket, Key, ContentType, }: {
|
|
11
|
+
ContentType?: string | undefined;
|
|
12
|
+
Body: string | Blob;
|
|
13
|
+
Bucket: string;
|
|
14
|
+
Key: string;
|
|
15
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.putS3Object = exports.getS3Object = exports.setS3 = void 0;
|
|
16
|
+
const aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
17
|
+
let s3 = new aws_sdk_1.default.S3();
|
|
18
|
+
const setS3 = (region) => {
|
|
19
|
+
s3 = new aws_sdk_1.default.S3({ region });
|
|
20
|
+
};
|
|
21
|
+
exports.setS3 = setS3;
|
|
22
|
+
const getS3Object = ({ fileurl, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
const content = yield s3.getObject(fileurl).promise();
|
|
24
|
+
return content;
|
|
25
|
+
});
|
|
26
|
+
exports.getS3Object = getS3Object;
|
|
27
|
+
const putS3Object = ({ Body, Bucket, Key, ContentType, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
yield s3
|
|
29
|
+
.putObject({
|
|
30
|
+
Body,
|
|
31
|
+
Bucket,
|
|
32
|
+
Key,
|
|
33
|
+
ContentType,
|
|
34
|
+
})
|
|
35
|
+
.promise();
|
|
36
|
+
});
|
|
37
|
+
exports.putS3Object = putS3Object;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runGenerator<T>(iter: AsyncGenerator<T[], T[], unknown>, partialRun: (value: T[]) => Promise<void>): Promise<void>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.runGenerator = void 0;
|
|
13
|
+
/* eslint-disable no-await-in-loop */
|
|
14
|
+
function runGenerator(iter, partialRun) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
let curr;
|
|
17
|
+
do {
|
|
18
|
+
curr = yield iter.next();
|
|
19
|
+
if (!(curr === null || curr === void 0 ? void 0 : curr.value) || curr.value.length === 0) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
yield partialRun(curr.value);
|
|
23
|
+
} while (!curr.done);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.runGenerator = runGenerator;
|
|
@@ -3,6 +3,7 @@ export * from './async';
|
|
|
3
3
|
export * from './date';
|
|
4
4
|
export * from './distinctBy';
|
|
5
5
|
export * from './email';
|
|
6
|
+
export * from './generator';
|
|
6
7
|
export * from './groupBy';
|
|
7
8
|
export * from './hashCode';
|
|
8
9
|
export * from './i18n';
|
|
@@ -11,4 +12,5 @@ export * from './math';
|
|
|
11
12
|
export * from './object';
|
|
12
13
|
export * from './random';
|
|
13
14
|
export * from './secondsInNearest';
|
|
15
|
+
export * from './sleep';
|
|
14
16
|
export * from './string';
|
|
@@ -15,6 +15,7 @@ __exportStar(require("./async"), exports);
|
|
|
15
15
|
__exportStar(require("./date"), exports);
|
|
16
16
|
__exportStar(require("./distinctBy"), exports);
|
|
17
17
|
__exportStar(require("./email"), exports);
|
|
18
|
+
__exportStar(require("./generator"), exports);
|
|
18
19
|
__exportStar(require("./groupBy"), exports);
|
|
19
20
|
__exportStar(require("./hashCode"), exports);
|
|
20
21
|
__exportStar(require("./i18n"), exports);
|
|
@@ -23,4 +24,5 @@ __exportStar(require("./math"), exports);
|
|
|
23
24
|
__exportStar(require("./object"), exports);
|
|
24
25
|
__exportStar(require("./random"), exports);
|
|
25
26
|
__exportStar(require("./secondsInNearest"), exports);
|
|
27
|
+
__exportStar(require("./sleep"), exports);
|
|
26
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,18 +16,12 @@ function useDebounce(value, delay) {
|
|
|
16
16
|
return debouncedValue;
|
|
17
17
|
}
|
|
18
18
|
exports.useDebounce = useDebounce;
|
|
19
|
-
const
|
|
20
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
21
|
-
};
|
|
22
|
-
exports.sleep = sleep;
|
|
23
|
-
const debounceMap = {};
|
|
19
|
+
const hashMap = {};
|
|
24
20
|
function debounce(callback, { key, time, }) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
debounceMap[key] = now;
|
|
31
|
-
callback();
|
|
21
|
+
clearTimeout(hashMap[key]);
|
|
22
|
+
hashMap[key] = setTimeout(() => {
|
|
23
|
+
delete hashMap[key];
|
|
24
|
+
callback();
|
|
25
|
+
}, time);
|
|
32
26
|
}
|
|
33
27
|
exports.debounce = debounce;
|