triangle-utils 1.4.44 → 1.4.45
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/dist/src/UtilsDynamoDB.d.ts +0 -3
- package/dist/src/UtilsDynamoDB.js +69 -58
- package/dist/src/f.js +3 -2
- package/package.json +1 -1
- package/src/UtilsDynamoDB.ts +72 -67
- package/src/f.ts +4 -2
|
@@ -15,7 +15,6 @@ export declare class UtilsDynamoDB {
|
|
|
15
15
|
query(table_index_name: string, primary_key: Record<string, any>, options?: {
|
|
16
16
|
reverse?: boolean;
|
|
17
17
|
compile?: boolean;
|
|
18
|
-
project?: boolean;
|
|
19
18
|
filters?: Record<string, any>;
|
|
20
19
|
undefined_attribute_names?: string[];
|
|
21
20
|
defined_attribute_names?: string[];
|
|
@@ -24,7 +23,6 @@ export declare class UtilsDynamoDB {
|
|
|
24
23
|
query_prefix(table_index_name: string, primary_key: Record<string, any>, secondary_key_prefix: Record<string, string>, options?: {
|
|
25
24
|
reverse?: boolean;
|
|
26
25
|
compile?: boolean;
|
|
27
|
-
project?: boolean;
|
|
28
26
|
filters?: Record<string, any>;
|
|
29
27
|
undefined_attribute_names?: string[];
|
|
30
28
|
defined_attribute_names?: string[];
|
|
@@ -33,7 +31,6 @@ export declare class UtilsDynamoDB {
|
|
|
33
31
|
query_range(table_index_name: string, primary_key: Record<string, any>, secondary_key_range: Record<string, (string | number)[]>, options?: {
|
|
34
32
|
reverse?: boolean;
|
|
35
33
|
compile?: boolean;
|
|
36
|
-
project?: boolean;
|
|
37
34
|
filters?: Record<string, any>;
|
|
38
35
|
undefined_attribute_names?: string[];
|
|
39
36
|
defined_attribute_names?: string[];
|
|
@@ -162,7 +162,7 @@ export class UtilsDynamoDB {
|
|
|
162
162
|
const table_name = table_index_name.split(":")[0];
|
|
163
163
|
const index_name = table_index_name.split(":")[1];
|
|
164
164
|
if (index_name === undefined && Object.keys(primary_key).length !== 1 ||
|
|
165
|
-
index_name !== undefined && Object.keys(primary_key).length !== index_name.split("-").length) {
|
|
165
|
+
index_name !== undefined && Object.keys(primary_key).length !== index_name.split(".")[0].split("-").length) {
|
|
166
166
|
return undefined;
|
|
167
167
|
}
|
|
168
168
|
const request = {
|
|
@@ -195,15 +195,10 @@ export class UtilsDynamoDB {
|
|
|
195
195
|
const defined_attribute_names = options.defined_attribute_names !== undefined ? options.defined_attribute_names : [];
|
|
196
196
|
const reverse = options.reverse !== undefined ? options.reverse : false;
|
|
197
197
|
const compile = options.compile !== undefined ? options.compile : true;
|
|
198
|
-
const project = options.project !== undefined ? options.project : false
|
|
198
|
+
// const project = options.project !== undefined ? options.project : false
|
|
199
199
|
const attribute_names = options.attribute_names !== undefined ? options.attribute_names : [];
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return [];
|
|
203
|
-
}
|
|
204
|
-
const key = Object.keys(primary_key)[0];
|
|
205
|
-
const value = convert_input(Object.values(primary_key)[0]);
|
|
206
|
-
if (value === undefined) {
|
|
200
|
+
if (index_name === undefined && Object.keys(primary_key).length !== 1 ||
|
|
201
|
+
index_name !== undefined && Object.keys(primary_key).length !== index_name.split(".")[0].split("-").length) {
|
|
207
202
|
return [];
|
|
208
203
|
}
|
|
209
204
|
const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ");
|
|
@@ -216,26 +211,31 @@ export class UtilsDynamoDB {
|
|
|
216
211
|
TableName: table_name,
|
|
217
212
|
IndexName: index_name,
|
|
218
213
|
ExpressionAttributeNames: {
|
|
219
|
-
"#
|
|
214
|
+
...Object.fromEntries(Object.keys(primary_key).map(key => ["#" + key, key])),
|
|
220
215
|
...Object.fromEntries(Object.keys(filters).map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
221
216
|
...Object.fromEntries(undefined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
222
217
|
...Object.fromEntries(defined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
223
218
|
...Object.fromEntries(attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name]))
|
|
224
219
|
},
|
|
225
220
|
ExpressionAttributeValues: {
|
|
226
|
-
|
|
221
|
+
...Object.fromEntries(Object.entries(primary_key)
|
|
222
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
223
|
+
.filter(([key, value]) => value !== undefined))
|
|
227
224
|
},
|
|
228
225
|
FilterExpression: filter_expression.length > 0 ? filter_expression : undefined,
|
|
229
226
|
ProjectionExpression: projection_expression.length > 0 ? projection_expression : undefined,
|
|
230
|
-
KeyConditionExpression: "#
|
|
227
|
+
KeyConditionExpression: Object.keys(primary_key).map(key => "#" + key + " = :" + key).join(" AND "),
|
|
231
228
|
ScanIndexForward: !reverse
|
|
232
229
|
};
|
|
233
|
-
const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile)
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
230
|
+
const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile);
|
|
231
|
+
// .then(async items => index_name === undefined || !project ? items :
|
|
232
|
+
// await Promise.all(items.map(async item => {
|
|
233
|
+
// return await this.get(table_name,
|
|
234
|
+
// Object.fromEntries(Object.entries(item).filter((([key_name, key_value]) => table_key_names.includes(key_name))))
|
|
235
|
+
// )
|
|
236
|
+
// }))
|
|
237
|
+
// .then(items => items.filter(item => item !== undefined))
|
|
238
|
+
// )
|
|
239
239
|
return items;
|
|
240
240
|
}
|
|
241
241
|
async query_prefix(table_index_name, primary_key, secondary_key_prefix, options = {}) {
|
|
@@ -243,18 +243,13 @@ export class UtilsDynamoDB {
|
|
|
243
243
|
const index_name = table_index_name.split(":")[1];
|
|
244
244
|
const reverse = options.reverse !== undefined ? options.reverse : false;
|
|
245
245
|
const compile = options.compile !== undefined ? options.compile : true;
|
|
246
|
-
const project = options.project !== undefined ? options.project : false
|
|
246
|
+
// const project = options.project !== undefined ? options.project : false
|
|
247
247
|
const filters = options.filters !== undefined ? options.filters : {};
|
|
248
248
|
const undefined_attribute_names = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : [];
|
|
249
249
|
const defined_attribute_names = options.defined_attribute_names !== undefined ? options.defined_attribute_names : [];
|
|
250
250
|
const attribute_names = options.attribute_names !== undefined ? options.attribute_names : [];
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
return [];
|
|
254
|
-
}
|
|
255
|
-
const converted_primary_value = convert_input(Object.values(primary_key)[0]);
|
|
256
|
-
const converted_secondary_prefix_value = convert_input(Object.values(secondary_key_prefix)[0]);
|
|
257
|
-
if (converted_primary_value === undefined || converted_secondary_prefix_value === undefined) {
|
|
251
|
+
if (index_name === undefined && Object.keys(primary_key).length !== 1 ||
|
|
252
|
+
index_name !== undefined && Object.keys(primary_key).length !== index_name.split(".")[0].split("-").length) {
|
|
258
253
|
return [];
|
|
259
254
|
}
|
|
260
255
|
const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ");
|
|
@@ -267,28 +262,38 @@ export class UtilsDynamoDB {
|
|
|
267
262
|
TableName: table_name,
|
|
268
263
|
IndexName: index_name,
|
|
269
264
|
ExpressionAttributeNames: {
|
|
270
|
-
|
|
271
|
-
|
|
265
|
+
...Object.fromEntries(Object.keys(primary_key).map(key => ["#" + key, key])),
|
|
266
|
+
...Object.fromEntries(Object.keys(secondary_key_prefix).map(key => ["#" + key, key])),
|
|
272
267
|
...Object.fromEntries(Object.keys(filters).map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
273
268
|
...Object.fromEntries(undefined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
274
269
|
...Object.fromEntries(defined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
275
270
|
...Object.fromEntries(attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name]))
|
|
276
271
|
},
|
|
277
272
|
ExpressionAttributeValues: {
|
|
278
|
-
|
|
279
|
-
|
|
273
|
+
...Object.fromEntries(Object.entries(primary_key)
|
|
274
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
275
|
+
.filter(([key, value]) => value !== undefined)),
|
|
276
|
+
...Object.fromEntries(Object.entries(secondary_key_prefix)
|
|
277
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
278
|
+
.filter(([key, value]) => value !== undefined))
|
|
280
279
|
},
|
|
281
280
|
FilterExpression: filter_expression.length > 0 ? filter_expression : undefined,
|
|
282
281
|
ProjectionExpression: projection_expression.length > 0 ? projection_expression : undefined,
|
|
283
|
-
KeyConditionExpression:
|
|
282
|
+
KeyConditionExpression: [
|
|
283
|
+
...Object.keys(primary_key).map(key => "#" + key + " = :" + key),
|
|
284
|
+
...Object.keys(secondary_key_prefix).map(key => "begins_with(#" + key + ", :" + key + ")")
|
|
285
|
+
].join(" AND "),
|
|
284
286
|
ScanIndexForward: !reverse
|
|
285
287
|
};
|
|
286
|
-
const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile)
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
288
|
+
const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile);
|
|
289
|
+
// .then(async items => index_name === undefined || !project ? items :
|
|
290
|
+
// await Promise.all(items.map(async item => {
|
|
291
|
+
// return await this.get(table_name,
|
|
292
|
+
// Object.fromEntries(Object.entries(item).filter((([key_name, key_value]) => table_key_names.includes(key_name))))
|
|
293
|
+
// )
|
|
294
|
+
// }))
|
|
295
|
+
// .then(items => items.filter(item => item !== undefined))
|
|
296
|
+
// )
|
|
292
297
|
return items;
|
|
293
298
|
}
|
|
294
299
|
async query_range(table_index_name, primary_key, secondary_key_range, options = {}) {
|
|
@@ -296,19 +301,13 @@ export class UtilsDynamoDB {
|
|
|
296
301
|
const index_name = table_index_name.split(":")[1];
|
|
297
302
|
const reverse = options.reverse !== undefined ? options.reverse : false;
|
|
298
303
|
const compile = options.compile !== undefined ? options.compile : true;
|
|
299
|
-
const project = options.project !== undefined ? options.project : false
|
|
304
|
+
// const project = options.project !== undefined ? options.project : false
|
|
300
305
|
const filters = options.filters !== undefined ? options.filters : {};
|
|
301
306
|
const undefined_attribute_names = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : [];
|
|
302
307
|
const defined_attribute_names = options.defined_attribute_names !== undefined ? options.defined_attribute_names : [];
|
|
303
308
|
const attribute_names = options.attribute_names !== undefined ? options.attribute_names : [];
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
return [];
|
|
307
|
-
}
|
|
308
|
-
const converted_primary_value = convert_input(Object.values(primary_key)[0]);
|
|
309
|
-
const converted_secondary_range_start_value = convert_input(Object.values(secondary_key_range)[0][0]);
|
|
310
|
-
const converted_secondary_range_end_value = convert_input(Object.values(secondary_key_range)[0][1]);
|
|
311
|
-
if (converted_primary_value === undefined || converted_secondary_range_start_value === undefined || converted_secondary_range_end_value === undefined) {
|
|
309
|
+
if (index_name === undefined && Object.keys(primary_key).length !== 1 ||
|
|
310
|
+
index_name !== undefined && Object.keys(primary_key).length !== index_name.split(".")[0].split("-").length) {
|
|
312
311
|
return [];
|
|
313
312
|
}
|
|
314
313
|
const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ");
|
|
@@ -321,29 +320,41 @@ export class UtilsDynamoDB {
|
|
|
321
320
|
TableName: table_name,
|
|
322
321
|
IndexName: index_name,
|
|
323
322
|
ExpressionAttributeNames: {
|
|
324
|
-
|
|
325
|
-
|
|
323
|
+
...Object.fromEntries(Object.keys(primary_key).map(key => ["#" + key, key])),
|
|
324
|
+
...Object.fromEntries(Object.keys(secondary_key_range).map(key => ["#" + key, key])),
|
|
326
325
|
...Object.fromEntries(Object.keys(filters).map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
327
326
|
...Object.fromEntries(undefined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
328
327
|
...Object.fromEntries(defined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
329
328
|
...Object.fromEntries(attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name]))
|
|
330
329
|
},
|
|
331
330
|
ExpressionAttributeValues: {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
331
|
+
...Object.fromEntries(Object.entries(primary_key)
|
|
332
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
333
|
+
.filter(([key, value]) => value !== undefined)),
|
|
334
|
+
...Object.fromEntries(Object.entries(secondary_key_range)
|
|
335
|
+
.map(([key, value]) => [":" + key + "_min", convert_input(value[0])])
|
|
336
|
+
.filter(([key, value]) => value !== undefined)),
|
|
337
|
+
...Object.fromEntries(Object.entries(secondary_key_range)
|
|
338
|
+
.map(([key, value]) => [":" + key + "_max", convert_input(value[1])])
|
|
339
|
+
.filter(([key, value]) => value !== undefined))
|
|
335
340
|
},
|
|
336
341
|
FilterExpression: filter_expression.length > 0 ? filter_expression : undefined,
|
|
337
342
|
ProjectionExpression: projection_expression.length > 0 ? projection_expression : undefined,
|
|
338
|
-
KeyConditionExpression:
|
|
343
|
+
KeyConditionExpression: [
|
|
344
|
+
...Object.keys(primary_key).map(key => "#" + key + " = :" + key),
|
|
345
|
+
...Object.keys(secondary_key_range).map(key => "(#" + key + " BETWEEN :" + key + "_min AND :" + key + "_max)")
|
|
346
|
+
].join(" AND "),
|
|
339
347
|
ScanIndexForward: !reverse
|
|
340
348
|
};
|
|
341
|
-
const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile)
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
349
|
+
const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile);
|
|
350
|
+
// .then(async items => index_name === undefined || !project ? items :
|
|
351
|
+
// await Promise.all(items.map(async item => {
|
|
352
|
+
// return await this.get(table_name,
|
|
353
|
+
// Object.fromEntries(Object.entries(item).filter((([key_name, key_value]) => table_key_names.includes(key_name))))
|
|
354
|
+
// )
|
|
355
|
+
// }))
|
|
356
|
+
// .then(items => items.filter(item => item !== undefined))
|
|
357
|
+
// )
|
|
347
358
|
return items;
|
|
348
359
|
}
|
|
349
360
|
async set(table_name, key, attributes) {
|
package/dist/src/f.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SecretsManager } from "@aws-sdk/client-secrets-manager";
|
|
2
2
|
import { TriangleUtils } from "./index.js";
|
|
3
|
+
console.log("Starting triangle-utils!");
|
|
3
4
|
const secret_name = "triage_config";
|
|
4
5
|
const secrets_manager = new SecretsManager({ region: "us-east-1" });
|
|
5
6
|
const response = await secrets_manager.getSecretValue({
|
|
@@ -15,5 +16,5 @@ const config = {
|
|
|
15
16
|
const utils = new TriangleUtils(config);
|
|
16
17
|
// const foods = await utils.dynamodb.query("triage_docket_documents:register_document_id", { register_document_id : "E6-17065" })
|
|
17
18
|
// console.log(foods)
|
|
18
|
-
const federal_donations = await utils.dynamodb.
|
|
19
|
-
console.log(federal_donations
|
|
19
|
+
const federal_donations = await utils.dynamodb.query("elections.federal_donations:donor_address_state_id-committee_id.federal_donation_id", { donor_address_state_id: "UT", committee_id: "C00401224" }, { compile: false, reverse: true });
|
|
20
|
+
console.log(federal_donations);
|
package/package.json
CHANGED
package/src/UtilsDynamoDB.ts
CHANGED
|
@@ -192,7 +192,7 @@ export class UtilsDynamoDB {
|
|
|
192
192
|
const table_name : string = table_index_name.split(":")[0]
|
|
193
193
|
const index_name : string | undefined = table_index_name.split(":")[1]
|
|
194
194
|
if (index_name === undefined && Object.keys(primary_key).length !== 1 ||
|
|
195
|
-
index_name !== undefined && Object.keys(primary_key).length !== index_name.split("-").length
|
|
195
|
+
index_name !== undefined && Object.keys(primary_key).length !== index_name.split(".")[0].split("-").length
|
|
196
196
|
) {
|
|
197
197
|
return undefined
|
|
198
198
|
}
|
|
@@ -227,7 +227,7 @@ export class UtilsDynamoDB {
|
|
|
227
227
|
options : {
|
|
228
228
|
reverse? : boolean,
|
|
229
229
|
compile? : boolean,
|
|
230
|
-
project? : boolean,
|
|
230
|
+
// project? : boolean,
|
|
231
231
|
filters? : Record<string, any>,
|
|
232
232
|
undefined_attribute_names? : string[],
|
|
233
233
|
defined_attribute_names? : string[],
|
|
@@ -241,16 +241,12 @@ export class UtilsDynamoDB {
|
|
|
241
241
|
const defined_attribute_names : string[] = options.defined_attribute_names !== undefined ? options.defined_attribute_names : []
|
|
242
242
|
const reverse = options.reverse !== undefined ? options.reverse : false
|
|
243
243
|
const compile = options.compile !== undefined ? options.compile : true
|
|
244
|
-
const project = options.project !== undefined ? options.project : false
|
|
244
|
+
// const project = options.project !== undefined ? options.project : false
|
|
245
245
|
const attribute_names : string[] = options.attribute_names !== undefined ? options.attribute_names : []
|
|
246
246
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
const key = Object.keys(primary_key)[0]
|
|
252
|
-
const value = convert_input(Object.values(primary_key)[0])
|
|
253
|
-
if (value === undefined) {
|
|
247
|
+
if (index_name === undefined && Object.keys(primary_key).length !== 1 ||
|
|
248
|
+
index_name !== undefined && Object.keys(primary_key).length !== index_name.split(".")[0].split("-").length
|
|
249
|
+
) {
|
|
254
250
|
return []
|
|
255
251
|
}
|
|
256
252
|
const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ")
|
|
@@ -263,29 +259,31 @@ export class UtilsDynamoDB {
|
|
|
263
259
|
TableName : table_name,
|
|
264
260
|
IndexName : index_name,
|
|
265
261
|
ExpressionAttributeNames: {
|
|
266
|
-
"#
|
|
262
|
+
...Object.fromEntries(Object.keys(primary_key).map(key => ["#" + key, key])),
|
|
267
263
|
...Object.fromEntries(Object.keys(filters).map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
268
264
|
...Object.fromEntries(undefined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
269
265
|
...Object.fromEntries(defined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
270
266
|
...Object.fromEntries(attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name]))
|
|
271
267
|
},
|
|
272
268
|
ExpressionAttributeValues: {
|
|
273
|
-
|
|
269
|
+
...Object.fromEntries(Object.entries(primary_key)
|
|
270
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
271
|
+
.filter(([key, value]) => value !== undefined))
|
|
274
272
|
},
|
|
275
273
|
FilterExpression : filter_expression.length > 0 ? filter_expression : undefined,
|
|
276
274
|
ProjectionExpression : projection_expression.length > 0 ? projection_expression : undefined,
|
|
277
|
-
KeyConditionExpression: "#
|
|
275
|
+
KeyConditionExpression: Object.keys(primary_key).map(key => "#" + key + " = :" + key).join(" AND "),
|
|
278
276
|
ScanIndexForward : !reverse
|
|
279
277
|
}
|
|
280
278
|
const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile)
|
|
281
|
-
.then(async items => index_name === undefined || !project ? items :
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
)
|
|
279
|
+
// .then(async items => index_name === undefined || !project ? items :
|
|
280
|
+
// await Promise.all(items.map(async item => {
|
|
281
|
+
// return await this.get(table_name,
|
|
282
|
+
// Object.fromEntries(Object.entries(item).filter((([key_name, key_value]) => table_key_names.includes(key_name))))
|
|
283
|
+
// )
|
|
284
|
+
// }))
|
|
285
|
+
// .then(items => items.filter(item => item !== undefined))
|
|
286
|
+
// )
|
|
289
287
|
return items
|
|
290
288
|
}
|
|
291
289
|
|
|
@@ -296,7 +294,7 @@ export class UtilsDynamoDB {
|
|
|
296
294
|
options : {
|
|
297
295
|
reverse? : boolean,
|
|
298
296
|
compile? : boolean,
|
|
299
|
-
project? : boolean,
|
|
297
|
+
// project? : boolean,
|
|
300
298
|
filters? : Record<string, any>,
|
|
301
299
|
undefined_attribute_names? : string[],
|
|
302
300
|
defined_attribute_names? : string[],
|
|
@@ -307,19 +305,15 @@ export class UtilsDynamoDB {
|
|
|
307
305
|
const index_name : string | undefined = table_index_name.split(":")[1]
|
|
308
306
|
const reverse = options.reverse !== undefined ? options.reverse : false
|
|
309
307
|
const compile = options.compile !== undefined ? options.compile : true
|
|
310
|
-
const project = options.project !== undefined ? options.project : false
|
|
308
|
+
// const project = options.project !== undefined ? options.project : false
|
|
311
309
|
const filters = options.filters !== undefined ? options.filters : {}
|
|
312
310
|
const undefined_attribute_names : string[] = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : []
|
|
313
311
|
const defined_attribute_names : string[] = options.defined_attribute_names !== undefined ? options.defined_attribute_names : []
|
|
314
312
|
const attribute_names : string[] = options.attribute_names !== undefined ? options.attribute_names : []
|
|
315
313
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
const converted_primary_value = convert_input(Object.values(primary_key)[0])
|
|
321
|
-
const converted_secondary_prefix_value = convert_input(Object.values(secondary_key_prefix)[0])
|
|
322
|
-
if (converted_primary_value === undefined || converted_secondary_prefix_value === undefined) {
|
|
314
|
+
if (index_name === undefined && Object.keys(primary_key).length !== 1 ||
|
|
315
|
+
index_name !== undefined && Object.keys(primary_key).length !== index_name.split(".")[0].split("-").length
|
|
316
|
+
) {
|
|
323
317
|
return []
|
|
324
318
|
}
|
|
325
319
|
const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ")
|
|
@@ -332,31 +326,38 @@ export class UtilsDynamoDB {
|
|
|
332
326
|
TableName : table_name,
|
|
333
327
|
IndexName : index_name,
|
|
334
328
|
ExpressionAttributeNames: {
|
|
335
|
-
|
|
336
|
-
|
|
329
|
+
...Object.fromEntries(Object.keys(primary_key).map(key => ["#" + key, key])),
|
|
330
|
+
...Object.fromEntries(Object.keys(secondary_key_prefix).map(key => ["#" + key, key])),
|
|
337
331
|
...Object.fromEntries(Object.keys(filters).map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
338
332
|
...Object.fromEntries(undefined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
339
333
|
...Object.fromEntries(defined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
340
334
|
...Object.fromEntries(attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name]))
|
|
341
335
|
},
|
|
342
336
|
ExpressionAttributeValues: {
|
|
343
|
-
|
|
344
|
-
|
|
337
|
+
...Object.fromEntries(Object.entries(primary_key)
|
|
338
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
339
|
+
.filter(([key, value]) => value !== undefined)),
|
|
340
|
+
...Object.fromEntries(Object.entries(secondary_key_prefix)
|
|
341
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
342
|
+
.filter(([key, value]) => value !== undefined))
|
|
345
343
|
},
|
|
346
344
|
FilterExpression : filter_expression.length > 0 ? filter_expression : undefined,
|
|
347
345
|
ProjectionExpression : projection_expression.length > 0 ? projection_expression : undefined,
|
|
348
|
-
KeyConditionExpression:
|
|
346
|
+
KeyConditionExpression: [
|
|
347
|
+
...Object.keys(primary_key).map(key => "#" + key + " = :" + key),
|
|
348
|
+
...Object.keys(secondary_key_prefix).map(key => "begins_with(#" + key + ", :" + key + ")")
|
|
349
|
+
].join(" AND "),
|
|
349
350
|
ScanIndexForward : !reverse
|
|
350
351
|
}
|
|
351
352
|
const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile)
|
|
352
|
-
.then(async items => index_name === undefined || !project ? items :
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
)
|
|
353
|
+
// .then(async items => index_name === undefined || !project ? items :
|
|
354
|
+
// await Promise.all(items.map(async item => {
|
|
355
|
+
// return await this.get(table_name,
|
|
356
|
+
// Object.fromEntries(Object.entries(item).filter((([key_name, key_value]) => table_key_names.includes(key_name))))
|
|
357
|
+
// )
|
|
358
|
+
// }))
|
|
359
|
+
// .then(items => items.filter(item => item !== undefined))
|
|
360
|
+
// )
|
|
360
361
|
return items
|
|
361
362
|
}
|
|
362
363
|
|
|
@@ -367,7 +368,7 @@ export class UtilsDynamoDB {
|
|
|
367
368
|
options : {
|
|
368
369
|
reverse? : boolean,
|
|
369
370
|
compile? : boolean,
|
|
370
|
-
project? : boolean,
|
|
371
|
+
// project? : boolean,
|
|
371
372
|
filters? : Record<string, any>,
|
|
372
373
|
undefined_attribute_names? : string[],
|
|
373
374
|
defined_attribute_names? : string[],
|
|
@@ -378,20 +379,15 @@ export class UtilsDynamoDB {
|
|
|
378
379
|
const index_name : string | undefined = table_index_name.split(":")[1]
|
|
379
380
|
const reverse = options.reverse !== undefined ? options.reverse : false
|
|
380
381
|
const compile = options.compile !== undefined ? options.compile : true
|
|
381
|
-
const project = options.project !== undefined ? options.project : false
|
|
382
|
+
// const project = options.project !== undefined ? options.project : false
|
|
382
383
|
const filters = options.filters !== undefined ? options.filters : {}
|
|
383
384
|
const undefined_attribute_names : string[] = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : []
|
|
384
385
|
const defined_attribute_names : string[] = options.defined_attribute_names !== undefined ? options.defined_attribute_names : []
|
|
385
386
|
const attribute_names : string[] = options.attribute_names !== undefined ? options.attribute_names : []
|
|
386
387
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
const converted_primary_value = convert_input(Object.values(primary_key)[0])
|
|
392
|
-
const converted_secondary_range_start_value = convert_input(Object.values(secondary_key_range)[0][0])
|
|
393
|
-
const converted_secondary_range_end_value = convert_input(Object.values(secondary_key_range)[0][1])
|
|
394
|
-
if (converted_primary_value === undefined || converted_secondary_range_start_value === undefined || converted_secondary_range_end_value === undefined) {
|
|
388
|
+
if (index_name === undefined && Object.keys(primary_key).length !== 1 ||
|
|
389
|
+
index_name !== undefined && Object.keys(primary_key).length !== index_name.split(".")[0].split("-").length
|
|
390
|
+
) {
|
|
395
391
|
return []
|
|
396
392
|
}
|
|
397
393
|
const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ")
|
|
@@ -404,32 +400,41 @@ export class UtilsDynamoDB {
|
|
|
404
400
|
TableName : table_name,
|
|
405
401
|
IndexName : index_name,
|
|
406
402
|
ExpressionAttributeNames: {
|
|
407
|
-
|
|
408
|
-
|
|
403
|
+
...Object.fromEntries(Object.keys(primary_key).map(key => ["#" + key, key])),
|
|
404
|
+
...Object.fromEntries(Object.keys(secondary_key_range).map(key => ["#" + key, key])),
|
|
409
405
|
...Object.fromEntries(Object.keys(filters).map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
410
406
|
...Object.fromEntries(undefined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
411
407
|
...Object.fromEntries(defined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
412
408
|
...Object.fromEntries(attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name]))
|
|
413
409
|
},
|
|
414
410
|
ExpressionAttributeValues: {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
411
|
+
...Object.fromEntries(Object.entries(primary_key)
|
|
412
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
413
|
+
.filter(([key, value]) => value !== undefined)),
|
|
414
|
+
...Object.fromEntries(Object.entries(secondary_key_range)
|
|
415
|
+
.map(([key, value]) => [":" + key + "_min", convert_input(value[0])])
|
|
416
|
+
.filter(([key, value]) => value !== undefined)),
|
|
417
|
+
...Object.fromEntries(Object.entries(secondary_key_range)
|
|
418
|
+
.map(([key, value]) => [":" + key + "_max", convert_input(value[1])])
|
|
419
|
+
.filter(([key, value]) => value !== undefined))
|
|
418
420
|
},
|
|
419
421
|
FilterExpression : filter_expression.length > 0 ? filter_expression : undefined,
|
|
420
422
|
ProjectionExpression : projection_expression.length > 0 ? projection_expression : undefined,
|
|
421
|
-
KeyConditionExpression:
|
|
423
|
+
KeyConditionExpression: [
|
|
424
|
+
...Object.keys(primary_key).map(key => "#" + key + " = :" + key),
|
|
425
|
+
...Object.keys(secondary_key_range).map(key => "(#" + key + " BETWEEN :" + key + "_min AND :" + key + "_max)")
|
|
426
|
+
].join(" AND "),
|
|
422
427
|
ScanIndexForward : !reverse
|
|
423
428
|
}
|
|
424
429
|
const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile)
|
|
425
|
-
.then(async items => index_name === undefined || !project ? items :
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
)
|
|
430
|
+
// .then(async items => index_name === undefined || !project ? items :
|
|
431
|
+
// await Promise.all(items.map(async item => {
|
|
432
|
+
// return await this.get(table_name,
|
|
433
|
+
// Object.fromEntries(Object.entries(item).filter((([key_name, key_value]) => table_key_names.includes(key_name))))
|
|
434
|
+
// )
|
|
435
|
+
// }))
|
|
436
|
+
// .then(items => items.filter(item => item !== undefined))
|
|
437
|
+
// )
|
|
433
438
|
return items
|
|
434
439
|
}
|
|
435
440
|
|
package/src/f.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { SecretsManager } from "@aws-sdk/client-secrets-manager"
|
|
2
2
|
import { TriangleUtils } from "."
|
|
3
3
|
|
|
4
|
+
console.log("Starting triangle-utils!")
|
|
5
|
+
|
|
4
6
|
const secret_name = "triage_config"
|
|
5
7
|
|
|
6
8
|
const secrets_manager = new SecretsManager({ region: "us-east-1" })
|
|
@@ -25,5 +27,5 @@ const utils = new TriangleUtils(config)
|
|
|
25
27
|
// console.log(foods)
|
|
26
28
|
|
|
27
29
|
|
|
28
|
-
const federal_donations = await utils.dynamodb.
|
|
29
|
-
console.log(federal_donations
|
|
30
|
+
const federal_donations = await utils.dynamodb.query("elections.federal_donations:donor_address_state_id-committee_id.federal_donation_id", { donor_address_state_id : "UT", committee_id : "C00401224" }, { compile : false, reverse : true })
|
|
31
|
+
console.log(federal_donations)
|