triangle-utils 1.4.73 → 1.4.75

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.
@@ -9,6 +9,7 @@ export declare class UtilsDynamoDB {
9
9
  attribute_names?: string[];
10
10
  segment_id?: number;
11
11
  num_segments?: number;
12
+ last_key?: Record<string, any>;
12
13
  }): Promise<Record<string, any>[]>;
13
14
  get(table: string, key: Record<string, any>, consistent?: boolean): Promise<Record<string, any> | undefined>;
14
15
  get_max(table_index_name: string, primary_key: Record<string, string | number>): Promise<Record<string, any> | undefined>;
@@ -19,6 +20,8 @@ export declare class UtilsDynamoDB {
19
20
  undefined_attribute_names?: string[];
20
21
  defined_attribute_names?: string[];
21
22
  attribute_names?: string[];
23
+ max_num_items?: number;
24
+ last_key?: Record<string, any>;
22
25
  }): Promise<Record<string, any>[]>;
23
26
  query_prefix(table_index_name: string, primary_key: Record<string, any>, secondary_key_prefix: Record<string, string>, options?: {
24
27
  reverse?: boolean;
@@ -27,6 +30,8 @@ export declare class UtilsDynamoDB {
27
30
  undefined_attribute_names?: string[];
28
31
  defined_attribute_names?: string[];
29
32
  attribute_names?: string[];
33
+ max_num_items?: number;
34
+ last_key?: Record<string, any>;
30
35
  }): Promise<Record<string, any>[]>;
31
36
  query_range(table_index_name: string, primary_key: Record<string, any>, secondary_key_range: Record<string, (string | number)[]>, options?: {
32
37
  reverse?: boolean;
@@ -35,6 +40,8 @@ export declare class UtilsDynamoDB {
35
40
  undefined_attribute_names?: string[];
36
41
  defined_attribute_names?: string[];
37
42
  attribute_names?: string[];
43
+ max_num_items?: number;
44
+ last_key?: Record<string, any>;
38
45
  }): Promise<Record<string, any>[]>;
39
46
  set(table_name: string, key: Record<string, any>, attributes: Record<string, any>): Promise<void>;
40
47
  append(table_name: string, key: Record<string, any>, attributes: Record<string, any[]>): Promise<void>;
@@ -64,7 +64,7 @@ function convert_input(input) {
64
64
  }
65
65
  async function compile_pages(request, f, compile = true) {
66
66
  const items = [];
67
- let last_eval_key = undefined;
67
+ let last_eval_key = request.ExclusiveStartKey;
68
68
  while (true) {
69
69
  const request_page = {
70
70
  ...request,
@@ -130,7 +130,8 @@ export class UtilsDynamoDB {
130
130
  FilterExpression: filter_expression.length > 0 ? filter_expression : undefined,
131
131
  ProjectionExpression: projection_expression.length > 0 ? projection_expression : undefined,
132
132
  Segment: i,
133
- TotalSegments: num_segments
133
+ TotalSegments: num_segments,
134
+ ExclusiveStartKey: options.last_key !== undefined ? convert_input(options.last_key)?.M : undefined
134
135
  };
135
136
  iterators.push(compile_pages(request, (request) => this.dynamodb.scan(request)));
136
137
  }
@@ -227,7 +228,9 @@ export class UtilsDynamoDB {
227
228
  FilterExpression: filter_expression.length > 0 ? filter_expression : undefined,
228
229
  ProjectionExpression: projection_expression.length > 0 ? projection_expression : undefined,
229
230
  KeyConditionExpression: Object.keys(primary_key).map(key => "#" + key + " = :" + key).join(" AND "),
230
- ScanIndexForward: !reverse
231
+ ScanIndexForward: !reverse,
232
+ Limit: options.max_num_items,
233
+ ExclusiveStartKey: options.last_key !== undefined ? convert_input(options.last_key)?.M : undefined
231
234
  };
232
235
  const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile);
233
236
  // .then(async items => index_name === undefined || !project ? items :
@@ -287,7 +290,9 @@ export class UtilsDynamoDB {
287
290
  ...Object.keys(primary_key).map(key => "#" + key + " = :" + key),
288
291
  ...Object.keys(secondary_key_prefix).map(key => "begins_with(#" + key + ", :" + key + ")")
289
292
  ].join(" AND "),
290
- ScanIndexForward: !reverse
293
+ ScanIndexForward: !reverse,
294
+ Limit: options.max_num_items,
295
+ ExclusiveStartKey: options.last_key !== undefined ? convert_input(options.last_key)?.M : undefined
291
296
  };
292
297
  const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile);
293
298
  // .then(async items => index_name === undefined || !project ? items :
@@ -350,7 +355,9 @@ export class UtilsDynamoDB {
350
355
  ...Object.keys(primary_key).map(key => "#" + key + " = :" + key),
351
356
  ...Object.keys(secondary_key_range).map(key => "(#" + key + " BETWEEN :" + key + "_min AND :" + key + "_max)")
352
357
  ].join(" AND "),
353
- ScanIndexForward: !reverse
358
+ ScanIndexForward: !reverse,
359
+ Limit: options.max_num_items,
360
+ ExclusiveStartKey: options.last_key !== undefined ? convert_input(options.last_key)?.M : undefined
354
361
  };
355
362
  const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile);
356
363
  // .then(async items => index_name === undefined || !project ? items :
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.73",
3
+ "version": "1.4.75",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -64,7 +64,7 @@ async function compile_pages(
64
64
  compile : boolean = true
65
65
  ) : Promise<any[]> {
66
66
  const items = []
67
- let last_eval_key : Record<string, AttributeValue> | undefined = undefined
67
+ let last_eval_key : Record<string, AttributeValue> | undefined = request.ExclusiveStartKey
68
68
  while (true) {
69
69
  const request_page : ScanCommandInput|QueryCommandInput = {
70
70
  ...request,
@@ -113,7 +113,8 @@ export class UtilsDynamoDB {
113
113
  defined_attribute_names? : string[],
114
114
  attribute_names? : string[],
115
115
  segment_id? : number
116
- num_segments? : number
116
+ num_segments? : number,
117
+ last_key? : Record<string, any>
117
118
  } = {}
118
119
  ) : Promise<Record<string, any>[]> {
119
120
  const table_name : string = table_index_name.split(":")[0]
@@ -151,7 +152,8 @@ export class UtilsDynamoDB {
151
152
  FilterExpression : filter_expression.length > 0 ? filter_expression : undefined,
152
153
  ProjectionExpression : projection_expression.length > 0 ? projection_expression : undefined,
153
154
  Segment : i,
154
- TotalSegments : num_segments
155
+ TotalSegments : num_segments,
156
+ ExclusiveStartKey : options.last_key !== undefined ? convert_input(options.last_key)?.M : undefined
155
157
  }
156
158
  iterators.push(compile_pages(request, (request : ScanCommandInput) => this.dynamodb.scan(request)))
157
159
  }
@@ -231,7 +233,9 @@ export class UtilsDynamoDB {
231
233
  filters? : Record<string, any>,
232
234
  undefined_attribute_names? : string[],
233
235
  defined_attribute_names? : string[],
234
- attribute_names? : string[]
236
+ attribute_names? : string[],
237
+ max_num_items? : number,
238
+ last_key? : Record<string, any>
235
239
  } = {}
236
240
  ) : Promise<Record<string, any>[]>{
237
241
  const table_name : string = table_index_name.split(":")[0]
@@ -275,7 +279,9 @@ export class UtilsDynamoDB {
275
279
  FilterExpression : filter_expression.length > 0 ? filter_expression : undefined,
276
280
  ProjectionExpression : projection_expression.length > 0 ? projection_expression : undefined,
277
281
  KeyConditionExpression: Object.keys(primary_key).map(key => "#" + key + " = :" + key).join(" AND "),
278
- ScanIndexForward : !reverse
282
+ ScanIndexForward : !reverse,
283
+ Limit : options.max_num_items,
284
+ ExclusiveStartKey : options.last_key !== undefined ? convert_input(options.last_key)?.M : undefined
279
285
  }
280
286
  const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile)
281
287
  // .then(async items => index_name === undefined || !project ? items :
@@ -300,7 +306,9 @@ export class UtilsDynamoDB {
300
306
  filters? : Record<string, any>,
301
307
  undefined_attribute_names? : string[],
302
308
  defined_attribute_names? : string[],
303
- attribute_names? : string[]
309
+ attribute_names? : string[],
310
+ max_num_items? : number,
311
+ last_key? : Record<string, any>
304
312
  } = {}
305
313
  ) : Promise<Record<string, any>[]>{
306
314
  const table_name : string = table_index_name.split(":")[0]
@@ -351,7 +359,9 @@ export class UtilsDynamoDB {
351
359
  ...Object.keys(primary_key).map(key => "#" + key + " = :" + key),
352
360
  ...Object.keys(secondary_key_prefix).map(key => "begins_with(#" + key + ", :" + key + ")")
353
361
  ].join(" AND "),
354
- ScanIndexForward : !reverse
362
+ ScanIndexForward : !reverse,
363
+ Limit : options.max_num_items,
364
+ ExclusiveStartKey : options.last_key !== undefined ? convert_input(options.last_key)?.M : undefined
355
365
  }
356
366
  const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile)
357
367
  // .then(async items => index_name === undefined || !project ? items :
@@ -376,7 +386,9 @@ export class UtilsDynamoDB {
376
386
  filters? : Record<string, any>,
377
387
  undefined_attribute_names? : string[],
378
388
  defined_attribute_names? : string[],
379
- attribute_names? : string[]
389
+ attribute_names? : string[],
390
+ max_num_items? : number,
391
+ last_key? : Record<string, any>
380
392
  } = {}
381
393
  ) : Promise<Record<string, any>[]>{
382
394
  const table_name : string = table_index_name.split(":")[0]
@@ -430,7 +442,9 @@ export class UtilsDynamoDB {
430
442
  ...Object.keys(primary_key).map(key => "#" + key + " = :" + key),
431
443
  ...Object.keys(secondary_key_range).map(key => "(#" + key + " BETWEEN :" + key + "_min AND :" + key + "_max)")
432
444
  ].join(" AND "),
433
- ScanIndexForward : !reverse
445
+ ScanIndexForward : !reverse,
446
+ Limit : options.max_num_items,
447
+ ExclusiveStartKey : options.last_key !== undefined ? convert_input(options.last_key)?.M : undefined
434
448
  }
435
449
  const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile)
436
450
  // .then(async items => index_name === undefined || !project ? items :