triangle-utils 1.0.33 → 1.0.35
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/package.json +3 -2
- package/test.js +4 -3
- package/utils/Utils_DynamoDB.js +28 -9
- package/utils/Utils_S3.js +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "triangle-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.35",
|
|
4
4
|
"main": "Utils.js",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"@aws-sdk/client-s3vectors": "^3.953.0",
|
|
14
14
|
"@aws-sdk/s3-request-presigner": "^3.953.0",
|
|
15
15
|
"nodemailer": "^7.0.11",
|
|
16
|
-
"scrapingbee": "^1.7.6"
|
|
16
|
+
"scrapingbee": "^1.7.6",
|
|
17
|
+
"triangle-utils": "^1.0.34"
|
|
17
18
|
}
|
|
18
19
|
}
|
package/test.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import Utils from "./Utils.js";
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
const utils = new Utils({ region : "us-east-
|
|
4
|
+
const utils = new Utils({ region : "us-east-1"})
|
|
5
5
|
|
|
6
|
-
const items = await utils.
|
|
6
|
+
const items = await utils.dynamodb.scan("candidates", { concurrency : 1, undefined_attribute_names : ["district"] })
|
|
7
|
+
// .then(items => items.filter(item => item.district === undefined))
|
|
7
8
|
|
|
8
|
-
console.log(items)
|
|
9
|
+
console.log(items.length)
|
package/utils/Utils_DynamoDB.js
CHANGED
|
@@ -62,15 +62,34 @@ export default class Utils_DynamoDB {
|
|
|
62
62
|
this.dynamodb = new DynamoDB({ region : config.region })
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
async scan(table,
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
65
|
+
async scan(table, options = {}) {
|
|
66
|
+
const filters = options.filters !== undefined ? options.filters : {}
|
|
67
|
+
const undefined_attribute_names = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : []
|
|
68
|
+
const defined_attribute_names = options.defined_attribute_names !== undefined ? options.defined_attribute_names : []
|
|
69
|
+
const concurrency = options.concurrency !== undefined ? options.concurrency : 1
|
|
70
|
+
const attribute_names = options.attribute_names !== undefined ? options.attribute_names : []
|
|
71
|
+
const iterators = []
|
|
72
|
+
for (let i = 0; i < concurrency; i++) {
|
|
73
|
+
const request = Object.fromEntries(Object.entries({
|
|
74
|
+
TableName : table,
|
|
75
|
+
ExpressionAttributeNames : Object.fromEntries(
|
|
76
|
+
[...Object.keys(filters), ...attribute_names, ...undefined_attribute_names, ...defined_attribute_names]
|
|
77
|
+
.map(attribute_name => ["#" + attribute_name, attribute_name])
|
|
78
|
+
),
|
|
79
|
+
ExpressionAttributeValues : Object.fromEntries(Object.entries(filters).map(([attribute_name, attribute_value]) => [":" + attribute_name, convert_input(attribute_value)])),
|
|
80
|
+
FilterExpression : [
|
|
81
|
+
...Object.keys(filters).map(attribute_name => "#" + attribute_name + " = :" + attribute_name),
|
|
82
|
+
...undefined_attribute_names.map(attribute_name => "attribute_not_exists(#" + attribute_name + ")"),
|
|
83
|
+
...defined_attribute_names.map(attribute_name => "attribute_exists(#" + attribute_name + ")")
|
|
84
|
+
].join(","),
|
|
85
|
+
ProjectionExpression : attribute_names.map(attribute_name => "#" + attribute_name).join(", "),
|
|
86
|
+
Segment : i,
|
|
87
|
+
TotalSegments : concurrency
|
|
88
|
+
}).filter(([field, value]) => value !== undefined && (typeof value === typeof 3 || Object.keys(value).length !== 0)))
|
|
89
|
+
iterators.push(paginate(request, (request) => this.dynamodb.scan(request)))
|
|
90
|
+
}
|
|
91
|
+
const segments = await Promise.all(iterators)
|
|
92
|
+
return segments.flat()
|
|
74
93
|
}
|
|
75
94
|
|
|
76
95
|
async get(table, key, consistent=false) {
|
package/utils/Utils_S3.js
CHANGED
|
@@ -17,7 +17,6 @@ export default class Utils_S3 {
|
|
|
17
17
|
this.s3 = new S3({ region : config.region })
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
21
20
|
async file_exists(s3_filename) {
|
|
22
21
|
const s3_key = parse_s3_filename(s3_filename)
|
|
23
22
|
if (s3_key === undefined) {
|
|
@@ -31,7 +30,6 @@ export default class Utils_S3 {
|
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
|
|
35
33
|
async get_file(s3_filename, json=false) {
|
|
36
34
|
const s3_key = parse_s3_filename(s3_filename)
|
|
37
35
|
if (s3_key === undefined) {
|