@@ -10,6 +10,7 @@ import { copyToClipboard } from '../../shared/utilities/messages'
10
10
import { DynamoDbTableNode } from '../explorer/dynamoDbTableNode'
11
11
import { DynamoDbClient } from '../../shared/clients/dynamoDbClient'
12
12
import { AttributeValue , Key , ScanInput } from 'aws-sdk/clients/dynamodb'
13
+ import { telemetry } from '../../shared/telemetry'
13
14
14
15
export interface RowData {
15
16
[ key : string ] : string
@@ -33,11 +34,12 @@ export interface TableSchema {
33
34
export async function getTableContent (
34
35
tableRequest : ScanInput ,
35
36
regionCode : string ,
37
+ tableSchema : TableSchema ,
36
38
client = new DynamoDbClient ( regionCode )
37
39
) {
38
40
tableRequest . Limit = await getMaxItemsPerPage ( )
39
41
const response = await client . scanTable ( tableRequest )
40
- const { columnNames, tableHeader } = getTableColumnsNames ( response )
42
+ const { columnNames, tableHeader } = getTableColumnsNames ( response , tableSchema )
41
43
const tableItems = getTableItems ( columnNames , response )
42
44
43
45
const tableData : TableData = {
@@ -48,25 +50,38 @@ export async function getTableContent(
48
50
return tableData
49
51
}
50
52
51
- export function getTableColumnsNames ( items : DynamoDB . Types . ScanOutput ) : {
53
+ export function getTableColumnsNames (
54
+ items : DynamoDB . Types . ScanOutput ,
55
+ tableSchema : TableSchema
56
+ ) : {
52
57
columnNames : Set < string >
53
58
tableHeader : RowData [ ]
54
59
} {
55
60
const tableColumnsNames = new Set < string > ( )
56
61
const tableHeader = [ ] as RowData [ ]
62
+ const response = {
63
+ columnNames : tableColumnsNames ,
64
+ tableHeader : tableHeader ,
65
+ }
66
+ if ( ! items . Items || items . Items . length === 0 ) {
67
+ return response
68
+ }
69
+ tableColumnsNames . add ( tableSchema . partitionKey . name )
70
+ if ( tableSchema . sortKey ) {
71
+ tableColumnsNames . add ( tableSchema . sortKey . name )
72
+ }
57
73
for ( const item of items . Items ?? [ ] ) {
58
74
for ( const key of Object . keys ( item ) ) {
59
- tableColumnsNames . add ( key )
75
+ if ( ! tableColumnsNames . has ( key ) ) {
76
+ tableColumnsNames . add ( key )
77
+ }
60
78
}
61
79
}
62
80
for ( const columnName of tableColumnsNames ) {
63
81
tableHeader . push ( { columnDataKey : columnName , title : columnName } )
64
82
}
65
83
66
- return {
67
- columnNames : tableColumnsNames ,
68
- tableHeader : tableHeader ,
69
- }
84
+ return response
70
85
}
71
86
72
87
export function getTableItems ( tableColumnsNames : Set < string > , items : DynamoDB . Types . ScanOutput ) {
@@ -92,24 +107,30 @@ export function getTableItems(tableColumnsNames: Set<string>, items: DynamoDB.Ty
92
107
* @param {DynamoDbTableNode } node - The DynamoDB table node containing table and region information.
93
108
*/
94
109
export async function copyDynamoDbArn ( node : DynamoDbTableNode , client = new DynamoDbClient ( node . regionCode ) ) {
95
- const response = await client . getTableInformation ( { TableName : node . dynamoDbtable } )
96
- if ( response . TableArn !== undefined ) {
97
- await copyToClipboard ( response . TableArn , 'ARN' )
98
- }
110
+ return telemetry . dynamodb_view . run ( async ( span ) => {
111
+ const response = await client . getTableInformation ( { TableName : node . dynamoDbtable } )
112
+ if ( response . TableArn !== undefined ) {
113
+ span . emit ( { dynamoDbTarget : 'tableProperties' , result : 'Succeeded' } )
114
+ await copyToClipboard ( response . TableArn , 'ARN' )
115
+ } else {
116
+ span . emit ( { dynamoDbTarget : 'tableProperties' , result : 'Failed' , reason : 'Table ARN is undefined' } )
117
+ }
118
+ } )
99
119
}
100
120
101
121
export async function queryTableContent (
102
122
queryRequest : { partitionKey : string ; sortKey : string } ,
103
123
regionCode : string ,
104
124
tableName : string ,
125
+ tableSchema : TableSchema ,
105
126
lastEvaluatedKey ?: Key ,
106
127
client = new DynamoDbClient ( regionCode )
107
128
) {
108
129
const queryRequestObject = await prepareQueryRequestObject ( tableName , regionCode , client , queryRequest )
109
130
queryRequestObject . Limit = await getMaxItemsPerPage ( )
110
131
queryRequestObject . ExclusiveStartKey = lastEvaluatedKey
111
132
const queryResponse = await client . queryTable ( queryRequestObject )
112
- const { columnNames, tableHeader } = getTableColumnsNames ( queryResponse )
133
+ const { columnNames, tableHeader } = getTableColumnsNames ( queryResponse , tableSchema )
113
134
const tableItems = getTableItems ( columnNames , queryResponse )
114
135
115
136
const tableData : TableData = {
0 commit comments