ag-common 0.0.354 → 0.0.356
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.
|
@@ -21,7 +21,15 @@ export declare const batchDelete: ({ tableName, breakOnError, pkName, keys, rang
|
|
|
21
21
|
} | {
|
|
22
22
|
error?: undefined;
|
|
23
23
|
}>;
|
|
24
|
-
export declare const scan: <T>(tableName: string
|
|
24
|
+
export declare const scan: <T>(tableName: string, opt?: {
|
|
25
|
+
filter?: {
|
|
26
|
+
filterExpression: string;
|
|
27
|
+
attrNames: Record<string, string>;
|
|
28
|
+
attrValues: Record<string, string>;
|
|
29
|
+
};
|
|
30
|
+
/** ProjectionExpression. will csv values */
|
|
31
|
+
requiredAttributeList?: string[];
|
|
32
|
+
}) => Promise<T[]>;
|
|
25
33
|
export declare const getItemDynamo: <T>({ tableName, pkName, pkValue, }: {
|
|
26
34
|
pkName: string;
|
|
27
35
|
pkValue: string;
|
|
@@ -144,15 +144,25 @@ const batchDelete = ({ tableName, breakOnError = true, pkName, keys, rangeName,
|
|
|
144
144
|
return {};
|
|
145
145
|
});
|
|
146
146
|
exports.batchDelete = batchDelete;
|
|
147
|
-
const scan = (tableName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
+
const scan = (tableName, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
148
148
|
const Items = [];
|
|
149
149
|
let ExclusiveStartKey;
|
|
150
150
|
do {
|
|
151
|
+
let params = {
|
|
152
|
+
TableName: tableName,
|
|
153
|
+
ExclusiveStartKey,
|
|
154
|
+
};
|
|
155
|
+
if (opt === null || opt === void 0 ? void 0 : opt.filter) {
|
|
156
|
+
params.FilterExpression = opt.filter.filterExpression;
|
|
157
|
+
params.ExpressionAttributeNames = opt.filter.attrNames;
|
|
158
|
+
params.ExpressionAttributeValues = opt.filter.attrValues;
|
|
159
|
+
}
|
|
160
|
+
if (opt === null || opt === void 0 ? void 0 : opt.requiredAttributeList) {
|
|
161
|
+
params.ProjectionExpression = opt.requiredAttributeList.join(', ');
|
|
162
|
+
}
|
|
151
163
|
const { Items: newitems, LastEvaluatedKey, $response,
|
|
152
164
|
// eslint-disable-next-line no-await-in-loop
|
|
153
|
-
} = yield exports.dynamoDb
|
|
154
|
-
.scan({ TableName: tableName, ExclusiveStartKey })
|
|
155
|
-
.promise();
|
|
165
|
+
} = yield exports.dynamoDb.scan(params).promise();
|
|
156
166
|
ExclusiveStartKey = LastEvaluatedKey;
|
|
157
167
|
if ($response.error && $response.error.statusCode) {
|
|
158
168
|
throw new Error($response.error.message);
|
package/dist/api/helpers/s3.js
CHANGED
|
@@ -86,7 +86,9 @@ const deleteFile = ({ Bucket, Key, }) => __awaiter(void 0, void 0, void 0, funct
|
|
|
86
86
|
});
|
|
87
87
|
exports.deleteFile = deleteFile;
|
|
88
88
|
const deleteFiles = ({ Bucket, Keys, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
var _a;
|
|
89
90
|
let toDelete = Keys.map((Key) => ({ Key }));
|
|
91
|
+
let deleted = 0;
|
|
90
92
|
while (toDelete.length > 0) {
|
|
91
93
|
const { part, rest } = (0, array_1.take)(toDelete, 900);
|
|
92
94
|
toDelete = rest;
|
|
@@ -96,9 +98,14 @@ const deleteFiles = ({ Bucket, Keys, }) => __awaiter(void 0, void 0, void 0, fun
|
|
|
96
98
|
Delete: { Objects: part },
|
|
97
99
|
})
|
|
98
100
|
.promise();
|
|
101
|
+
if (!((_a = res.Deleted) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
102
|
+
throw new Error('no deleted files');
|
|
103
|
+
}
|
|
104
|
+
deleted += res.Deleted.length;
|
|
99
105
|
if (res.$response.error) {
|
|
100
106
|
return { error: res.$response.error.message };
|
|
101
107
|
}
|
|
108
|
+
(0, log_1.info)(`deleted ${deleted} files`);
|
|
102
109
|
}
|
|
103
110
|
return {};
|
|
104
111
|
});
|