ag-common 0.0.638 → 0.0.640
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.
|
@@ -143,16 +143,15 @@ const batchDelete = ({ tableName, keys, pkName, }) => __awaiter(void 0, void 0,
|
|
|
143
143
|
});
|
|
144
144
|
exports.batchDelete = batchDelete;
|
|
145
145
|
const scan = (tableName, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
146
|
-
var _a;
|
|
147
146
|
try {
|
|
148
147
|
let ExclusiveStartKey;
|
|
149
148
|
let Items = [];
|
|
150
149
|
do {
|
|
151
|
-
let params = new lib_dynamodb_1.ScanCommand(Object.assign(Object.assign(Object.assign({ TableName: tableName }, ((opt === null || opt === void 0 ? void 0 : opt.filter) && Object.assign({ FilterExpression: opt.filter.filterExpression, ExpressionAttributeNames: opt.filter.attrNames }, (opt.filter.attrValues && {
|
|
150
|
+
let params = new lib_dynamodb_1.ScanCommand(Object.assign(Object.assign(Object.assign(Object.assign({ TableName: tableName }, ((opt === null || opt === void 0 ? void 0 : opt.filter) && Object.assign({ FilterExpression: opt.filter.filterExpression, ExpressionAttributeNames: opt.filter.attrNames }, (opt.filter.attrValues && {
|
|
152
151
|
ExpressionAttributeValues: opt.filter.attrValues,
|
|
153
152
|
})))), ((opt === null || opt === void 0 ? void 0 : opt.requiredAttributeList) && {
|
|
154
153
|
ProjectionExpression: opt.requiredAttributeList.join(', '),
|
|
155
|
-
})), { ExclusiveStartKey,
|
|
154
|
+
})), { ExclusiveStartKey }), ((opt === null || opt === void 0 ? void 0 : opt.limit) && { Limit: opt.limit })));
|
|
156
155
|
(0, log_1.debug)(`running dynamo scan=${JSON.stringify(params, null, 2)}`);
|
|
157
156
|
const { Items: newitems, LastEvaluatedKey,
|
|
158
157
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -161,10 +160,9 @@ const scan = (tableName, opt) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
161
160
|
if (newitems) {
|
|
162
161
|
Items.push(...newitems.map((r) => r));
|
|
163
162
|
}
|
|
164
|
-
} while (ExclusiveStartKey &&
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
({ part: Items } = (0, array_1.take)(Items, opt === null || opt === void 0 ? void 0 : opt.maxCount));
|
|
163
|
+
} while (ExclusiveStartKey && (!(opt === null || opt === void 0 ? void 0 : opt.limit) || Items.length < opt.limit));
|
|
164
|
+
if (opt === null || opt === void 0 ? void 0 : opt.limit) {
|
|
165
|
+
({ part: Items } = (0, array_1.take)(Items, opt === null || opt === void 0 ? void 0 : opt.limit));
|
|
168
166
|
}
|
|
169
167
|
(0, log_1.debug)(`dynamo scan against ${tableName} ok, count=${Items === null || Items === void 0 ? void 0 : Items.length}`);
|
|
170
168
|
return { data: Items };
|
|
@@ -176,7 +174,7 @@ const scan = (tableName, opt) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
176
174
|
});
|
|
177
175
|
exports.scan = scan;
|
|
178
176
|
const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
179
|
-
var
|
|
177
|
+
var _a, _b;
|
|
180
178
|
const params = new lib_dynamodb_1.BatchGetCommand({
|
|
181
179
|
RequestItems: {
|
|
182
180
|
[tableName]: {
|
|
@@ -188,7 +186,7 @@ const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void
|
|
|
188
186
|
});
|
|
189
187
|
try {
|
|
190
188
|
let res = yield exports.dynamoDb.send(params);
|
|
191
|
-
let data = (
|
|
189
|
+
let data = (_b = (_a = res.Responses) === null || _a === void 0 ? void 0 : _a[tableName].map((r) => r)) !== null && _b !== void 0 ? _b : [];
|
|
192
190
|
return { data };
|
|
193
191
|
}
|
|
194
192
|
catch (e) {
|
|
@@ -251,7 +249,7 @@ const queryDynamo = ({ tableName, pkName, pkValue, pkOperator = '=', skName, skV
|
|
|
251
249
|
}
|
|
252
250
|
const Items = [];
|
|
253
251
|
do {
|
|
254
|
-
const params = new lib_dynamodb_1.QueryCommand(Object.assign(Object.assign(Object.assign({ TableName: tableName, KeyConditionExpression: kce, ExpressionAttributeNames: ean, ExpressionAttributeValues: eav, ScanIndexForward: sortAscending,
|
|
252
|
+
const params = new lib_dynamodb_1.QueryCommand(Object.assign(Object.assign(Object.assign(Object.assign({ TableName: tableName, KeyConditionExpression: kce, ExpressionAttributeNames: ean, ExpressionAttributeValues: eav, ScanIndexForward: sortAscending }, (limit !== null && limit !== -1 && { Limit: limit || 1000 })), (indexName && { IndexName: indexName })), (startKey && {
|
|
255
253
|
ExclusiveStartKey: startKey,
|
|
256
254
|
})), (FilterExpression && { FilterExpression })));
|
|
257
255
|
let lek;
|
|
@@ -284,7 +282,7 @@ exports.getDynamoTtlDays = getDynamoTtlDays;
|
|
|
284
282
|
const getDynamoTtlMinutes = (mins) => Math.ceil(new Date().getTime() / 1000) + mins * 60;
|
|
285
283
|
exports.getDynamoTtlMinutes = getDynamoTtlMinutes;
|
|
286
284
|
const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
287
|
-
var
|
|
285
|
+
var _c;
|
|
288
286
|
try {
|
|
289
287
|
let infoV = yield exports.dynamoDb.send(new client_dynamodb_1.DescribeTableCommand({ TableName: tableName }));
|
|
290
288
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -298,7 +296,7 @@ const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
298
296
|
throw allraw.error;
|
|
299
297
|
}
|
|
300
298
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
301
|
-
let all = ((
|
|
299
|
+
let all = ((_c = allraw === null || allraw === void 0 ? void 0 : allraw.data) === null || _c === void 0 ? void 0 : _c.map((d) => d)) || [];
|
|
302
300
|
(0, log_1.warn)(`will delete ${all === null || all === void 0 ? void 0 : all.length} items from ${tableName}`);
|
|
303
301
|
yield (0, exports.batchDelete)({
|
|
304
302
|
tableName,
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.640",
|
|
3
3
|
"name": "ag-common",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"license": "ISC",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"preinstall": "npx only-allow pnpm",
|
|
11
|
-
"format": "eslint --ext .ts,.tsx
|
|
11
|
+
"format": "eslint --ext .ts,.tsx src --fix",
|
|
12
12
|
"lint:tsc": "tsc --noEmit",
|
|
13
|
-
"lint:eslint": "eslint --ext .ts,.tsx
|
|
13
|
+
"lint:eslint": "eslint --ext .ts,.tsx src",
|
|
14
14
|
"lint": "pnpm run /^lint:/",
|
|
15
15
|
"build": "rimraf dist && tsc -p tsconfig.build.json",
|
|
16
16
|
"start": "cross-env BROWSER=none cross-env storybook dev -p 6006",
|