triangle-utils 1.0.35 → 1.0.37

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "main": "Utils.js",
5
5
  "author": "",
6
6
  "license": "ISC",
package/test.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import Utils from "./Utils.js";
2
2
 
3
3
 
4
- const utils = new Utils({ region : "us-east-1"})
4
+ const utils = new Utils({ region : "us-east-2"})
5
5
 
6
- const items = await utils.dynamodb.scan("candidates", { concurrency : 1, undefined_attribute_names : ["district"] })
7
- // .then(items => items.filter(item => item.district === undefined))
6
+ const jurisdiction_documents = await utils.dynamodb.scan("jurisdiction_documents", {
7
+ defined_attribute_names : ["s3_filename"],
8
+ undefined_attribute_names : ["vector_keys"]
9
+ })
8
10
 
9
- console.log(items.length)
11
+ console.log(jurisdiction_documents.length)
@@ -38,7 +38,7 @@ function convert_input(input) {
38
38
  return undefined
39
39
  }
40
40
 
41
- async function paginate(request, f) {
41
+ async function compile_pages(request, f, compile = true) {
42
42
  const items = []
43
43
  let last_eval_key = undefined
44
44
  while (true) {
@@ -49,7 +49,7 @@ async function paginate(request, f) {
49
49
  )
50
50
  const new_items = response.Items.map(item => convert_output({ M : item }))
51
51
  items.push(...new_items)
52
- if (response.LastEvaluatedKey === undefined) {
52
+ if (response.LastEvaluatedKey === undefined || !compile) {
53
53
  return items
54
54
  }
55
55
  last_eval_key = response.LastEvaluatedKey
@@ -81,12 +81,12 @@ export default class Utils_DynamoDB {
81
81
  ...Object.keys(filters).map(attribute_name => "#" + attribute_name + " = :" + attribute_name),
82
82
  ...undefined_attribute_names.map(attribute_name => "attribute_not_exists(#" + attribute_name + ")"),
83
83
  ...defined_attribute_names.map(attribute_name => "attribute_exists(#" + attribute_name + ")")
84
- ].join(","),
84
+ ].join(" AND "),
85
85
  ProjectionExpression : attribute_names.map(attribute_name => "#" + attribute_name).join(", "),
86
86
  Segment : i,
87
87
  TotalSegments : concurrency
88
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)))
89
+ iterators.push(compile_pages(request, (request) => this.dynamodb.scan(request)))
90
90
  }
91
91
  const segments = await Promise.all(iterators)
92
92
  return segments.flat()
@@ -131,7 +131,9 @@ export default class Utils_DynamoDB {
131
131
 
132
132
 
133
133
 
134
- async query(table, primary_key, reverse=false) {
134
+ async query(table, primary_key, options = {}) {
135
+ const reverse = options.reverse !== undefined ? options.reverse : false
136
+ const compile = options.reverse !== undefined ? options.compile : true
135
137
  if (Object.keys(primary_key).length !== 1) {
136
138
  return undefined
137
139
  }
@@ -146,7 +148,7 @@ export default class Utils_DynamoDB {
146
148
  KeyConditionExpression: "#a = :a",
147
149
  ScanIndexForward : !reverse
148
150
  }
149
- return await paginate(request, (request) => this.dynamodb.query(request))
151
+ return await compile_pages(request, (request) => this.dynamodb.query(request), compile)
150
152
  }
151
153
 
152
154
  async query_prefix(table, primary_key, secondary_key_prefix, reverse=false) {
@@ -166,7 +168,7 @@ export default class Utils_DynamoDB {
166
168
  KeyConditionExpression: "#a = :a AND begins_with(#b, :b)",
167
169
  ScanIndexForward : !reverse
168
170
  }
169
- return await paginate(request, (request) => this.dynamodb.query(request))
171
+ return await compile_pages(request, (request) => this.dynamodb.query(request))
170
172
  }
171
173
 
172
174
  async query_range(table, primary_key, secondary_key_range, reverse=false) {
@@ -187,7 +189,7 @@ export default class Utils_DynamoDB {
187
189
  KeyConditionExpression: "#a = :a AND (#b BETWEEN :b1 AND :b2)",
188
190
  ScanIndexForward : !reverse
189
191
  }
190
- return await paginate(request, (request) => this.dynamodb.query(request))
192
+ return await compile_pages(request, (request) => this.dynamodb.query(request))
191
193
  }
192
194
 
193
195
  async set(table, key, attributes) {