triangle-utils 1.4.77 → 1.4.79
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.
|
@@ -3,15 +3,19 @@ export declare class UtilsDynamoDB {
|
|
|
3
3
|
constructor(region: string);
|
|
4
4
|
get_table_key_names(table_name: string): Promise<string[] | undefined>;
|
|
5
5
|
scan(table_index_name: string, options?: {
|
|
6
|
+
compile?: boolean;
|
|
6
7
|
filters?: Record<string, any>;
|
|
7
8
|
undefined_attribute_names?: string[];
|
|
8
9
|
defined_attribute_names?: string[];
|
|
9
10
|
attribute_names?: string[];
|
|
10
11
|
segment_id?: number;
|
|
11
12
|
num_segments?: number;
|
|
13
|
+
max_num_items?: number;
|
|
12
14
|
last_key?: Record<string, any>;
|
|
13
15
|
}): Promise<Record<string, any>[]>;
|
|
14
|
-
get(table: string, key: Record<string, any>,
|
|
16
|
+
get(table: string, key: Record<string, any>, options?: {
|
|
17
|
+
consistent?: boolean;
|
|
18
|
+
}): Promise<Record<string, any> | undefined>;
|
|
15
19
|
get_max(table_index_name: string, primary_key: Record<string, string | number>): Promise<Record<string, any> | undefined>;
|
|
16
20
|
query(table_index_name: string, primary_key: Record<string, any>, options?: {
|
|
17
21
|
reverse?: boolean;
|
|
@@ -101,6 +101,7 @@ export class UtilsDynamoDB {
|
|
|
101
101
|
async scan(table_index_name, options = {}) {
|
|
102
102
|
const table_name = table_index_name.split(":")[0];
|
|
103
103
|
const index_name = table_index_name.split(":")[1];
|
|
104
|
+
const compile = options.compile !== undefined ? options.compile : true;
|
|
104
105
|
const filters = options.filters !== undefined ? options.filters : {};
|
|
105
106
|
const undefined_attribute_names = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : [];
|
|
106
107
|
const defined_attribute_names = options.defined_attribute_names !== undefined ? options.defined_attribute_names : [];
|
|
@@ -131,15 +132,17 @@ export class UtilsDynamoDB {
|
|
|
131
132
|
ProjectionExpression: projection_expression.length > 0 ? projection_expression : undefined,
|
|
132
133
|
Segment: i,
|
|
133
134
|
TotalSegments: num_segments,
|
|
135
|
+
Limit: options.max_num_items,
|
|
134
136
|
ExclusiveStartKey: options.last_key !== undefined ? convert_input(options.last_key)?.M : undefined
|
|
135
137
|
};
|
|
136
|
-
iterators.push(compile_pages(request, (request) => this.dynamodb.scan(request)));
|
|
138
|
+
iterators.push(compile_pages(request, (request) => this.dynamodb.scan(request), compile));
|
|
137
139
|
}
|
|
138
140
|
const segments = await Promise.all(iterators);
|
|
139
141
|
const items = segments.flat().filter(is_item);
|
|
140
142
|
return items;
|
|
141
143
|
}
|
|
142
|
-
async get(table, key,
|
|
144
|
+
async get(table, key, options = {}) {
|
|
145
|
+
const consistent = options.consistent !== undefined ? options.consistent : false;
|
|
143
146
|
const converted_key = convert_input(key)?.M;
|
|
144
147
|
if (converted_key === undefined) {
|
|
145
148
|
return undefined;
|
|
@@ -409,7 +412,7 @@ export class UtilsDynamoDB {
|
|
|
409
412
|
this.dynamodb.updateItem(request);
|
|
410
413
|
}
|
|
411
414
|
async add(table_name, key, attributes) {
|
|
412
|
-
const item = await this.get(table_name, key, true);
|
|
415
|
+
const item = await this.get(table_name, key, { consistent: true });
|
|
413
416
|
if (item === undefined) {
|
|
414
417
|
return;
|
|
415
418
|
}
|
|
@@ -441,7 +444,7 @@ export class UtilsDynamoDB {
|
|
|
441
444
|
await this.dynamodb.updateItem(request);
|
|
442
445
|
}
|
|
443
446
|
async create(table_name, key, attributes = {}) {
|
|
444
|
-
const item = await this.get(table_name, key, true);
|
|
447
|
+
const item = await this.get(table_name, key, { consistent: true });
|
|
445
448
|
if (item !== undefined) {
|
|
446
449
|
return;
|
|
447
450
|
}
|
package/package.json
CHANGED
package/src/UtilsDynamoDB.ts
CHANGED
|
@@ -108,17 +108,20 @@ export class UtilsDynamoDB {
|
|
|
108
108
|
async scan(
|
|
109
109
|
table_index_name : string,
|
|
110
110
|
options : {
|
|
111
|
+
compile? : boolean,
|
|
111
112
|
filters? : Record<string, any>,
|
|
112
113
|
undefined_attribute_names? : string[],
|
|
113
114
|
defined_attribute_names? : string[],
|
|
114
115
|
attribute_names? : string[],
|
|
115
116
|
segment_id? : number
|
|
116
117
|
num_segments? : number,
|
|
118
|
+
max_num_items? : number,
|
|
117
119
|
last_key? : Record<string, any>
|
|
118
120
|
} = {}
|
|
119
121
|
) : Promise<Record<string, any>[]> {
|
|
120
122
|
const table_name : string = table_index_name.split(":")[0]
|
|
121
123
|
const index_name : string | undefined = table_index_name.split(":")[1]
|
|
124
|
+
const compile = options.compile !== undefined ? options.compile : true
|
|
122
125
|
const filters = options.filters !== undefined ? options.filters : {}
|
|
123
126
|
const undefined_attribute_names : string[] = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : []
|
|
124
127
|
const defined_attribute_names : string[] = options.defined_attribute_names !== undefined ? options.defined_attribute_names : []
|
|
@@ -153,9 +156,10 @@ export class UtilsDynamoDB {
|
|
|
153
156
|
ProjectionExpression : projection_expression.length > 0 ? projection_expression : undefined,
|
|
154
157
|
Segment : i,
|
|
155
158
|
TotalSegments : num_segments,
|
|
159
|
+
Limit : options.max_num_items,
|
|
156
160
|
ExclusiveStartKey : options.last_key !== undefined ? convert_input(options.last_key)?.M : undefined
|
|
157
161
|
}
|
|
158
|
-
iterators.push(compile_pages(request, (request : ScanCommandInput) => this.dynamodb.scan(request)))
|
|
162
|
+
iterators.push(compile_pages(request, (request : ScanCommandInput) => this.dynamodb.scan(request), compile))
|
|
159
163
|
}
|
|
160
164
|
const segments = await Promise.all(iterators)
|
|
161
165
|
const items = segments.flat().filter(is_item)
|
|
@@ -165,8 +169,11 @@ export class UtilsDynamoDB {
|
|
|
165
169
|
async get(
|
|
166
170
|
table : string,
|
|
167
171
|
key : Record<string, any>,
|
|
168
|
-
|
|
172
|
+
options : {
|
|
173
|
+
consistent? : boolean
|
|
174
|
+
} = {}
|
|
169
175
|
) : Promise<Record<string, any> | undefined> {
|
|
176
|
+
const consistent = options.consistent !== undefined ? options.consistent : false
|
|
170
177
|
const converted_key = convert_input(key)?.M
|
|
171
178
|
if (converted_key === undefined) {
|
|
172
179
|
return undefined
|
|
@@ -506,7 +513,7 @@ export class UtilsDynamoDB {
|
|
|
506
513
|
}
|
|
507
514
|
|
|
508
515
|
async add(table_name : string, key : Record<string, any>, attributes : Record<string, any[]>) : Promise<void> {
|
|
509
|
-
const item = await this.get(table_name, key, true)
|
|
516
|
+
const item = await this.get(table_name, key, { consistent : true })
|
|
510
517
|
if (item === undefined) {
|
|
511
518
|
return
|
|
512
519
|
}
|
|
@@ -542,7 +549,7 @@ export class UtilsDynamoDB {
|
|
|
542
549
|
}
|
|
543
550
|
|
|
544
551
|
async create(table_name : string, key : Record<string, any>, attributes : Record<string, any> = {}) : Promise<void> {
|
|
545
|
-
const item = await this.get(table_name, key, true)
|
|
552
|
+
const item = await this.get(table_name, key, { consistent : true })
|
|
546
553
|
if (item !== undefined) {
|
|
547
554
|
return
|
|
548
555
|
}
|