triangle-utils 1.4.21 → 1.4.22
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 +9 -0
- package/dist/src/UtilsDynamoDB.js +36 -0
- package/package.json +1 -1
- package/src/UtilsDynamoDB.ts +45 -0
|
@@ -15,18 +15,27 @@ export declare class UtilsDynamoDB {
|
|
|
15
15
|
reverse?: boolean;
|
|
16
16
|
compile?: boolean;
|
|
17
17
|
project?: boolean;
|
|
18
|
+
filters?: Record<string, any>;
|
|
19
|
+
undefined_attribute_names?: string[];
|
|
20
|
+
defined_attribute_names?: string[];
|
|
18
21
|
attribute_names?: string[];
|
|
19
22
|
}): Promise<Record<string, any>[]>;
|
|
20
23
|
query_prefix(table_index_name: string, primary_key: Record<string, any>, secondary_key_prefix: Record<string, string>, options?: {
|
|
21
24
|
reverse?: boolean;
|
|
22
25
|
compile?: boolean;
|
|
23
26
|
project?: boolean;
|
|
27
|
+
filters?: Record<string, any>;
|
|
28
|
+
undefined_attribute_names?: string[];
|
|
29
|
+
defined_attribute_names?: string[];
|
|
24
30
|
attribute_names?: string[];
|
|
25
31
|
}): Promise<Record<string, any>[]>;
|
|
26
32
|
query_range(table_index_name: string, primary_key: Record<string, any>, secondary_key_range: Record<string, (string | number)[]>, options?: {
|
|
27
33
|
reverse?: boolean;
|
|
28
34
|
compile?: boolean;
|
|
29
35
|
project?: boolean;
|
|
36
|
+
filters?: Record<string, any>;
|
|
37
|
+
undefined_attribute_names?: string[];
|
|
38
|
+
defined_attribute_names?: string[];
|
|
30
39
|
attribute_names?: string[];
|
|
31
40
|
}): Promise<Record<string, any>[]>;
|
|
32
41
|
set(table_name: string, key: Record<string, any>, attributes: Record<string, any>): Promise<void>;
|
|
@@ -190,6 +190,9 @@ export class UtilsDynamoDB {
|
|
|
190
190
|
async query(table_index_name, primary_key, options = {}) {
|
|
191
191
|
const table_name = table_index_name.split(":")[0];
|
|
192
192
|
const index_name = table_index_name.split(":")[1];
|
|
193
|
+
const filters = options.filters !== undefined ? options.filters : {};
|
|
194
|
+
const undefined_attribute_names = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : [];
|
|
195
|
+
const defined_attribute_names = options.defined_attribute_names !== undefined ? options.defined_attribute_names : [];
|
|
193
196
|
const reverse = options.reverse !== undefined ? options.reverse : false;
|
|
194
197
|
const compile = options.compile !== undefined ? options.compile : true;
|
|
195
198
|
const project = options.project !== undefined ? options.project : true;
|
|
@@ -204,16 +207,25 @@ export class UtilsDynamoDB {
|
|
|
204
207
|
return [];
|
|
205
208
|
}
|
|
206
209
|
const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ");
|
|
210
|
+
const filter_expression = [
|
|
211
|
+
...Object.keys(filters).map(attribute_name => "#" + attribute_name + " = :" + attribute_name),
|
|
212
|
+
...undefined_attribute_names.map(attribute_name => "attribute_not_exists(#" + attribute_name + ")"),
|
|
213
|
+
...defined_attribute_names.map(attribute_name => "attribute_exists(#" + attribute_name + ")")
|
|
214
|
+
].join(" AND ");
|
|
207
215
|
const request = {
|
|
208
216
|
TableName: table_name,
|
|
209
217
|
IndexName: index_name,
|
|
210
218
|
ExpressionAttributeNames: {
|
|
211
219
|
"#a": key,
|
|
220
|
+
...Object.fromEntries(Object.keys(filters).map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
221
|
+
...Object.fromEntries(undefined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
222
|
+
...Object.fromEntries(defined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
212
223
|
...Object.fromEntries(attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name]))
|
|
213
224
|
},
|
|
214
225
|
ExpressionAttributeValues: {
|
|
215
226
|
":a": value
|
|
216
227
|
},
|
|
228
|
+
FilterExpression: filter_expression.length > 0 ? filter_expression : undefined,
|
|
217
229
|
ProjectionExpression: projection_expression.length > 0 ? projection_expression : undefined,
|
|
218
230
|
KeyConditionExpression: "#a = :a",
|
|
219
231
|
ScanIndexForward: !reverse
|
|
@@ -232,6 +244,9 @@ export class UtilsDynamoDB {
|
|
|
232
244
|
const reverse = options.reverse !== undefined ? options.reverse : false;
|
|
233
245
|
const compile = options.compile !== undefined ? options.compile : true;
|
|
234
246
|
const project = options.project !== undefined ? options.project : true;
|
|
247
|
+
const filters = options.filters !== undefined ? options.filters : {};
|
|
248
|
+
const undefined_attribute_names = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : [];
|
|
249
|
+
const defined_attribute_names = options.defined_attribute_names !== undefined ? options.defined_attribute_names : [];
|
|
235
250
|
const attribute_names = options.attribute_names !== undefined ? options.attribute_names : [];
|
|
236
251
|
const table_key_names = await this.get_table_key_names(table_name);
|
|
237
252
|
if (table_key_names === undefined || Object.keys(primary_key).length !== 1 || Object.keys(secondary_key_prefix).length !== 1) {
|
|
@@ -243,18 +258,27 @@ export class UtilsDynamoDB {
|
|
|
243
258
|
return [];
|
|
244
259
|
}
|
|
245
260
|
const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ");
|
|
261
|
+
const filter_expression = [
|
|
262
|
+
...Object.keys(filters).map(attribute_name => "#" + attribute_name + " = :" + attribute_name),
|
|
263
|
+
...undefined_attribute_names.map(attribute_name => "attribute_not_exists(#" + attribute_name + ")"),
|
|
264
|
+
...defined_attribute_names.map(attribute_name => "attribute_exists(#" + attribute_name + ")")
|
|
265
|
+
].join(" AND ");
|
|
246
266
|
const request = {
|
|
247
267
|
TableName: table_name,
|
|
248
268
|
IndexName: index_name,
|
|
249
269
|
ExpressionAttributeNames: {
|
|
250
270
|
"#a": Object.keys(primary_key)[0],
|
|
251
271
|
"#b": Object.keys(secondary_key_prefix)[0],
|
|
272
|
+
...Object.fromEntries(Object.keys(filters).map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
273
|
+
...Object.fromEntries(undefined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
274
|
+
...Object.fromEntries(defined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
252
275
|
...Object.fromEntries(attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name]))
|
|
253
276
|
},
|
|
254
277
|
ExpressionAttributeValues: {
|
|
255
278
|
":a": converted_primary_value,
|
|
256
279
|
":b": converted_secondary_prefix_value
|
|
257
280
|
},
|
|
281
|
+
FilterExpression: filter_expression.length > 0 ? filter_expression : undefined,
|
|
258
282
|
ProjectionExpression: projection_expression.length > 0 ? projection_expression : undefined,
|
|
259
283
|
KeyConditionExpression: "#a = :a AND begins_with(#b, :b)",
|
|
260
284
|
ScanIndexForward: !reverse
|
|
@@ -273,6 +297,9 @@ export class UtilsDynamoDB {
|
|
|
273
297
|
const reverse = options.reverse !== undefined ? options.reverse : false;
|
|
274
298
|
const compile = options.compile !== undefined ? options.compile : true;
|
|
275
299
|
const project = options.project !== undefined ? options.project : true;
|
|
300
|
+
const filters = options.filters !== undefined ? options.filters : {};
|
|
301
|
+
const undefined_attribute_names = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : [];
|
|
302
|
+
const defined_attribute_names = options.defined_attribute_names !== undefined ? options.defined_attribute_names : [];
|
|
276
303
|
const attribute_names = options.attribute_names !== undefined ? options.attribute_names : [];
|
|
277
304
|
const table_key_names = await this.get_table_key_names(table_name);
|
|
278
305
|
if (table_key_names === undefined || Object.keys(primary_key).length !== 1 || Object.keys(secondary_key_range).length !== 1 || Object.values(secondary_key_range)[0].length !== 2) {
|
|
@@ -285,12 +312,20 @@ export class UtilsDynamoDB {
|
|
|
285
312
|
return [];
|
|
286
313
|
}
|
|
287
314
|
const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ");
|
|
315
|
+
const filter_expression = [
|
|
316
|
+
...Object.keys(filters).map(attribute_name => "#" + attribute_name + " = :" + attribute_name),
|
|
317
|
+
...undefined_attribute_names.map(attribute_name => "attribute_not_exists(#" + attribute_name + ")"),
|
|
318
|
+
...defined_attribute_names.map(attribute_name => "attribute_exists(#" + attribute_name + ")")
|
|
319
|
+
].join(" AND ");
|
|
288
320
|
const request = {
|
|
289
321
|
TableName: table_name,
|
|
290
322
|
IndexName: index_name,
|
|
291
323
|
ExpressionAttributeNames: {
|
|
292
324
|
"#a": Object.keys(primary_key)[0],
|
|
293
325
|
"#b": Object.keys(secondary_key_range)[0],
|
|
326
|
+
...Object.fromEntries(Object.keys(filters).map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
327
|
+
...Object.fromEntries(undefined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
328
|
+
...Object.fromEntries(defined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
294
329
|
...Object.fromEntries(attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name]))
|
|
295
330
|
},
|
|
296
331
|
ExpressionAttributeValues: {
|
|
@@ -298,6 +333,7 @@ export class UtilsDynamoDB {
|
|
|
298
333
|
":b1": converted_secondary_range_start_value,
|
|
299
334
|
":b2": converted_secondary_range_end_value
|
|
300
335
|
},
|
|
336
|
+
FilterExpression: filter_expression.length > 0 ? filter_expression : undefined,
|
|
301
337
|
ProjectionExpression: projection_expression.length > 0 ? projection_expression : undefined,
|
|
302
338
|
KeyConditionExpression: "#a = :a AND (#b BETWEEN :b1 AND :b2)",
|
|
303
339
|
ScanIndexForward: !reverse
|
package/package.json
CHANGED
package/src/UtilsDynamoDB.ts
CHANGED
|
@@ -224,11 +224,17 @@ export class UtilsDynamoDB {
|
|
|
224
224
|
reverse? : boolean,
|
|
225
225
|
compile? : boolean,
|
|
226
226
|
project? : boolean,
|
|
227
|
+
filters? : Record<string, any>,
|
|
228
|
+
undefined_attribute_names? : string[],
|
|
229
|
+
defined_attribute_names? : string[],
|
|
227
230
|
attribute_names? : string[]
|
|
228
231
|
} = {}
|
|
229
232
|
) : Promise<Record<string, any>[]>{
|
|
230
233
|
const table_name : string = table_index_name.split(":")[0]
|
|
231
234
|
const index_name : string | undefined = table_index_name.split(":")[1]
|
|
235
|
+
const filters = options.filters !== undefined ? options.filters : {}
|
|
236
|
+
const undefined_attribute_names : string[] = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : []
|
|
237
|
+
const defined_attribute_names : string[] = options.defined_attribute_names !== undefined ? options.defined_attribute_names : []
|
|
232
238
|
const reverse = options.reverse !== undefined ? options.reverse : false
|
|
233
239
|
const compile = options.compile !== undefined ? options.compile : true
|
|
234
240
|
const project = options.project !== undefined ? options.project : true
|
|
@@ -244,16 +250,25 @@ export class UtilsDynamoDB {
|
|
|
244
250
|
return []
|
|
245
251
|
}
|
|
246
252
|
const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ")
|
|
253
|
+
const filter_expression = [
|
|
254
|
+
...Object.keys(filters).map(attribute_name => "#" + attribute_name + " = :" + attribute_name),
|
|
255
|
+
...undefined_attribute_names.map(attribute_name => "attribute_not_exists(#" + attribute_name + ")"),
|
|
256
|
+
...defined_attribute_names.map(attribute_name => "attribute_exists(#" + attribute_name + ")")
|
|
257
|
+
].join(" AND ")
|
|
247
258
|
const request : QueryCommandInput = {
|
|
248
259
|
TableName : table_name,
|
|
249
260
|
IndexName : index_name,
|
|
250
261
|
ExpressionAttributeNames: {
|
|
251
262
|
"#a": key,
|
|
263
|
+
...Object.fromEntries(Object.keys(filters).map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
264
|
+
...Object.fromEntries(undefined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
265
|
+
...Object.fromEntries(defined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
252
266
|
...Object.fromEntries(attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name]))
|
|
253
267
|
},
|
|
254
268
|
ExpressionAttributeValues: {
|
|
255
269
|
":a": value
|
|
256
270
|
},
|
|
271
|
+
FilterExpression : filter_expression.length > 0 ? filter_expression : undefined,
|
|
257
272
|
ProjectionExpression : projection_expression.length > 0 ? projection_expression : undefined,
|
|
258
273
|
KeyConditionExpression: "#a = :a",
|
|
259
274
|
ScanIndexForward : !reverse
|
|
@@ -278,6 +293,9 @@ export class UtilsDynamoDB {
|
|
|
278
293
|
reverse? : boolean,
|
|
279
294
|
compile? : boolean,
|
|
280
295
|
project? : boolean,
|
|
296
|
+
filters? : Record<string, any>,
|
|
297
|
+
undefined_attribute_names? : string[],
|
|
298
|
+
defined_attribute_names? : string[],
|
|
281
299
|
attribute_names? : string[]
|
|
282
300
|
} = {}
|
|
283
301
|
) : Promise<Record<string, any>[]>{
|
|
@@ -286,6 +304,9 @@ export class UtilsDynamoDB {
|
|
|
286
304
|
const reverse = options.reverse !== undefined ? options.reverse : false
|
|
287
305
|
const compile = options.compile !== undefined ? options.compile : true
|
|
288
306
|
const project = options.project !== undefined ? options.project : true
|
|
307
|
+
const filters = options.filters !== undefined ? options.filters : {}
|
|
308
|
+
const undefined_attribute_names : string[] = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : []
|
|
309
|
+
const defined_attribute_names : string[] = options.defined_attribute_names !== undefined ? options.defined_attribute_names : []
|
|
289
310
|
const attribute_names : string[] = options.attribute_names !== undefined ? options.attribute_names : []
|
|
290
311
|
|
|
291
312
|
const table_key_names = await this.get_table_key_names(table_name)
|
|
@@ -298,18 +319,27 @@ export class UtilsDynamoDB {
|
|
|
298
319
|
return []
|
|
299
320
|
}
|
|
300
321
|
const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ")
|
|
322
|
+
const filter_expression = [
|
|
323
|
+
...Object.keys(filters).map(attribute_name => "#" + attribute_name + " = :" + attribute_name),
|
|
324
|
+
...undefined_attribute_names.map(attribute_name => "attribute_not_exists(#" + attribute_name + ")"),
|
|
325
|
+
...defined_attribute_names.map(attribute_name => "attribute_exists(#" + attribute_name + ")")
|
|
326
|
+
].join(" AND ")
|
|
301
327
|
const request : QueryCommandInput = {
|
|
302
328
|
TableName : table_name,
|
|
303
329
|
IndexName : index_name,
|
|
304
330
|
ExpressionAttributeNames: {
|
|
305
331
|
"#a": Object.keys(primary_key)[0],
|
|
306
332
|
"#b": Object.keys(secondary_key_prefix)[0],
|
|
333
|
+
...Object.fromEntries(Object.keys(filters).map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
334
|
+
...Object.fromEntries(undefined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
335
|
+
...Object.fromEntries(defined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
307
336
|
...Object.fromEntries(attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name]))
|
|
308
337
|
},
|
|
309
338
|
ExpressionAttributeValues: {
|
|
310
339
|
":a": converted_primary_value,
|
|
311
340
|
":b": converted_secondary_prefix_value
|
|
312
341
|
},
|
|
342
|
+
FilterExpression : filter_expression.length > 0 ? filter_expression : undefined,
|
|
313
343
|
ProjectionExpression : projection_expression.length > 0 ? projection_expression : undefined,
|
|
314
344
|
KeyConditionExpression: "#a = :a AND begins_with(#b, :b)",
|
|
315
345
|
ScanIndexForward : !reverse
|
|
@@ -334,6 +364,9 @@ export class UtilsDynamoDB {
|
|
|
334
364
|
reverse? : boolean,
|
|
335
365
|
compile? : boolean,
|
|
336
366
|
project? : boolean,
|
|
367
|
+
filters? : Record<string, any>,
|
|
368
|
+
undefined_attribute_names? : string[],
|
|
369
|
+
defined_attribute_names? : string[],
|
|
337
370
|
attribute_names? : string[]
|
|
338
371
|
} = {}
|
|
339
372
|
) : Promise<Record<string, any>[]>{
|
|
@@ -342,6 +375,9 @@ export class UtilsDynamoDB {
|
|
|
342
375
|
const reverse = options.reverse !== undefined ? options.reverse : false
|
|
343
376
|
const compile = options.compile !== undefined ? options.compile : true
|
|
344
377
|
const project = options.project !== undefined ? options.project : true
|
|
378
|
+
const filters = options.filters !== undefined ? options.filters : {}
|
|
379
|
+
const undefined_attribute_names : string[] = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : []
|
|
380
|
+
const defined_attribute_names : string[] = options.defined_attribute_names !== undefined ? options.defined_attribute_names : []
|
|
345
381
|
const attribute_names : string[] = options.attribute_names !== undefined ? options.attribute_names : []
|
|
346
382
|
|
|
347
383
|
const table_key_names = await this.get_table_key_names(table_name)
|
|
@@ -355,12 +391,20 @@ export class UtilsDynamoDB {
|
|
|
355
391
|
return []
|
|
356
392
|
}
|
|
357
393
|
const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ")
|
|
394
|
+
const filter_expression = [
|
|
395
|
+
...Object.keys(filters).map(attribute_name => "#" + attribute_name + " = :" + attribute_name),
|
|
396
|
+
...undefined_attribute_names.map(attribute_name => "attribute_not_exists(#" + attribute_name + ")"),
|
|
397
|
+
...defined_attribute_names.map(attribute_name => "attribute_exists(#" + attribute_name + ")")
|
|
398
|
+
].join(" AND ")
|
|
358
399
|
const request : QueryCommandInput = {
|
|
359
400
|
TableName : table_name,
|
|
360
401
|
IndexName : index_name,
|
|
361
402
|
ExpressionAttributeNames: {
|
|
362
403
|
"#a": Object.keys(primary_key)[0],
|
|
363
404
|
"#b": Object.keys(secondary_key_range)[0],
|
|
405
|
+
...Object.fromEntries(Object.keys(filters).map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
406
|
+
...Object.fromEntries(undefined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
407
|
+
...Object.fromEntries(defined_attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
364
408
|
...Object.fromEntries(attribute_names.map(attribute_name => ["#" + attribute_name, attribute_name]))
|
|
365
409
|
},
|
|
366
410
|
ExpressionAttributeValues: {
|
|
@@ -368,6 +412,7 @@ export class UtilsDynamoDB {
|
|
|
368
412
|
":b1": converted_secondary_range_start_value,
|
|
369
413
|
":b2": converted_secondary_range_end_value
|
|
370
414
|
},
|
|
415
|
+
FilterExpression : filter_expression.length > 0 ? filter_expression : undefined,
|
|
371
416
|
ProjectionExpression : projection_expression.length > 0 ? projection_expression : undefined,
|
|
372
417
|
KeyConditionExpression: "#a = :a AND (#b BETWEEN :b1 AND :b2)",
|
|
373
418
|
ScanIndexForward : !reverse
|