Skip to content
This repository was archived by the owner on Dec 1, 2022. It is now read-only.

Commit 1afd43e

Browse files
committed
Refactored #25 into helper function and fixed flow issues
1 parent f3202c4 commit 1afd43e

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/Provisioner.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,7 @@ export default class Provisioner extends ProvisionerConfigurableBase {
2020
async getTableNamesAsync(): Promise<string[]> {
2121

2222
// Option 1 - All tables (Default)
23-
// The output from ListTables is paginated, with each page
24-
// returning a maximum of 100 table names.
25-
let listTablesResponse = await this.db.listTablesAsync();
26-
var tableNames = listTablesResponse.TableNames;
27-
var lastTable = listTablesResponse.LastEvaluatedTableName;
28-
29-
while (lastTable) {
30-
var params = { ExclusiveStartTableName: lastTable };
31-
let listTablesResponse = await this.db.listTablesAsync(params);
32-
tableNames = tableNames.concat(listTablesResponse.TableNames);
33-
lastTable = listTablesResponse.LastEvaluatedTableName;
34-
}
35-
36-
return tableNames;
23+
return await this.db.listAllTableNamesAsync();
3724

3825
// Option 2 - Hardcoded list of tables
3926
// return ['Table1', 'Table2', 'Table3'];

src/aws/DynamoDB.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ export default class DynamoDB {
4646
}
4747
}
4848

49+
async listAllTableNamesAsync(): Promise<string[]> {
50+
let tableNames = [];
51+
let lastTable;
52+
do {
53+
let listTablesResponse = await this.listTablesAsync({ ExclusiveStartTableName: lastTable });
54+
tableNames = tableNames.concat(listTablesResponse.TableNames);
55+
lastTable = listTablesResponse.LastEvaluatedTableName;
56+
} while (lastTable);
57+
return tableNames;
58+
}
59+
4960
async describeTableAsync(params: DescribeTableRequest): Promise<DescribeTableResponse> {
5061
let sw = stats.timer('DynamoDB.describeTableAsync').start();
5162
try {

0 commit comments

Comments
 (0)