ag-common 0.0.310 → 0.0.313
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.
|
@@ -36,7 +36,7 @@ export declare const getItemsDynamo: <T>({ tableName, items, }: {
|
|
|
36
36
|
}[];
|
|
37
37
|
tableName: string;
|
|
38
38
|
}) => Promise<T[]>;
|
|
39
|
-
export declare const queryDynamo: <T>({ tableName, pkName, pkValue, pkOperator, skName, skValue, skOperator, indexName, count, startKey: startKeyIn, filterName, filterValue, filterOperator, }: IQueryDynamo) => Promise<{
|
|
39
|
+
export declare const queryDynamo: <T>({ tableName, pkName, pkValue, pkOperator, skName, skValue, skOperator, indexName, count, startKey: startKeyIn, filterName, filterValue, filterOperator, sortAscending, }: IQueryDynamo) => Promise<{
|
|
40
40
|
Items: T[];
|
|
41
41
|
startKey?: Key | undefined;
|
|
42
42
|
}>;
|
|
@@ -42,7 +42,7 @@ const putDynamo = (item, tableName) => __awaiter(void 0, void 0, void 0, functio
|
|
|
42
42
|
return { data: item };
|
|
43
43
|
});
|
|
44
44
|
exports.putDynamo = putDynamo;
|
|
45
|
-
let batchWriteRaw = (req
|
|
45
|
+
let batchWriteRaw = (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
46
|
let count = 0;
|
|
47
47
|
let max = 5;
|
|
48
48
|
// eslint-disable-next-line no-constant-condition
|
|
@@ -58,20 +58,20 @@ let batchWriteRaw = (req, debugMsg) => __awaiter(void 0, void 0, void 0, functio
|
|
|
58
58
|
catch (e) {
|
|
59
59
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
60
|
let es = e.toString();
|
|
61
|
+
let msg = es;
|
|
62
|
+
(0, log_1.warn)('dynamo write error', msg);
|
|
61
63
|
if (es.indexOf('429') !== -1 ||
|
|
62
64
|
es.indexOf('ProvisionedThroughputExceeded') !== -1) {
|
|
63
65
|
count += 1;
|
|
66
|
+
msg = `batch write throttled. retry ${count}/${max}`;
|
|
64
67
|
}
|
|
65
|
-
|
|
68
|
+
else {
|
|
66
69
|
throw e;
|
|
67
70
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
(0, log_1.info)(msg);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
debugMsg(msg);
|
|
71
|
+
if (count >= max) {
|
|
72
|
+
throw e;
|
|
74
73
|
}
|
|
74
|
+
(0, log_1.warn)(`dynamo retry ${count}/${max}`);
|
|
75
75
|
yield (0, sleep_1.sleep)(2000);
|
|
76
76
|
}
|
|
77
77
|
});
|
|
@@ -90,7 +90,7 @@ const batchWrite = (tableName, itemsIn, breakOnError = false) => __awaiter(void
|
|
|
90
90
|
PutRequest: { Item: item },
|
|
91
91
|
})),
|
|
92
92
|
};
|
|
93
|
-
let res = yield batchWriteRaw(req
|
|
93
|
+
let res = yield batchWriteRaw(req);
|
|
94
94
|
const newError = (_b = (_a = res.$response) === null || _a === void 0 ? void 0 : _a.error) !== null && _b !== void 0 ? _b : null;
|
|
95
95
|
if (newError) {
|
|
96
96
|
error.push(newError);
|
|
@@ -212,19 +212,7 @@ const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void
|
|
|
212
212
|
}
|
|
213
213
|
});
|
|
214
214
|
exports.getItemsDynamo = getItemsDynamo;
|
|
215
|
-
const queryDynamo = ({ tableName, pkName, pkValue,
|
|
216
|
-
/**
|
|
217
|
-
* default =
|
|
218
|
-
*/
|
|
219
|
-
pkOperator = '=', skName, skValue,
|
|
220
|
-
/**
|
|
221
|
-
* default =
|
|
222
|
-
*/
|
|
223
|
-
skOperator = '=', indexName, count = 1000, startKey: startKeyIn, filterName, filterValue,
|
|
224
|
-
/**
|
|
225
|
-
* default =
|
|
226
|
-
*/
|
|
227
|
-
filterOperator = '=', }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
215
|
+
const queryDynamo = ({ tableName, pkName, pkValue, pkOperator = '=', skName, skValue, skOperator = '=', indexName, count = 1000, startKey: startKeyIn, filterName, filterValue, filterOperator = '=', sortAscending = true, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
228
216
|
var _g, _h;
|
|
229
217
|
let startKey = startKeyIn;
|
|
230
218
|
let kce = `#${pkName.toLowerCase()} ${pkOperator} :${pkName.toLowerCase()}`;
|
|
@@ -278,6 +266,7 @@ filterOperator = '=', }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
278
266
|
ExpressionAttributeValues: eav,
|
|
279
267
|
ExclusiveStartKey: startKey,
|
|
280
268
|
FilterExpression,
|
|
269
|
+
ScanIndexForward: sortAscending,
|
|
281
270
|
};
|
|
282
271
|
if (count > 0) {
|
|
283
272
|
params.Limit = count;
|
|
@@ -54,16 +54,22 @@ export declare type TSkOperator = 'BETWEEN' | '<' | '<=' | '=' | '>=' | '>' | '<
|
|
|
54
54
|
export interface IQueryDynamo {
|
|
55
55
|
pkName: string;
|
|
56
56
|
pkValue: string | number;
|
|
57
|
+
/** default, = */
|
|
57
58
|
pkOperator?: string;
|
|
58
59
|
skName?: string;
|
|
59
60
|
skValue?: string | number | string[] | number[];
|
|
61
|
+
/** default, = */
|
|
60
62
|
skOperator?: TSkOperator;
|
|
61
63
|
tableName: string;
|
|
62
64
|
indexName?: string;
|
|
65
|
+
/** default 1000 */
|
|
63
66
|
count?: number;
|
|
64
67
|
startKey?: Key;
|
|
65
68
|
filterName?: string;
|
|
66
69
|
filterValue?: string | number | boolean;
|
|
70
|
+
/** default, = */
|
|
67
71
|
filterOperator?: string;
|
|
72
|
+
/** default = true */
|
|
73
|
+
sortAscending?: boolean;
|
|
68
74
|
}
|
|
69
75
|
export * from './aws';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.313",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -42,14 +42,14 @@
|
|
|
42
42
|
"@storybook/react": "6.5.10",
|
|
43
43
|
"@storybook/theming": "6.5.10",
|
|
44
44
|
"@types/jsonwebtoken": "8.5.8",
|
|
45
|
-
"@types/node": "18.7.
|
|
45
|
+
"@types/node": "18.7.5",
|
|
46
46
|
"@types/react": "18.0.17",
|
|
47
47
|
"@types/react-dom": "18.0.6",
|
|
48
48
|
"@types/styled-components": "5.1.26",
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "5.33.
|
|
50
|
-
"@typescript-eslint/parser": "5.33.
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "5.33.1",
|
|
50
|
+
"@typescript-eslint/parser": "5.33.1",
|
|
51
51
|
"cross-env": "7.0.3",
|
|
52
|
-
"eslint": "8.
|
|
52
|
+
"eslint": "8.22.0",
|
|
53
53
|
"eslint-config-airbnb-typescript": "17.0.0",
|
|
54
54
|
"eslint-config-prettier": "8.5.0",
|
|
55
55
|
"eslint-plugin-import": "2.26.0",
|