mapbox / dyno

simple dynamodb client
MIT License
78 stars 28 forks source link

Update reduceCapacity to support new data shape #157

Closed AlexanderBelokon closed 1 year ago

AlexanderBelokon commented 2 years ago

When using batch operations the stats are not returned correctly.

For example, this request:

batchWriteAll({
  RequestItems: { ... },
  ReturnConsumedCapacity: 'INDEXES',
  ReturnItemCollectionMetrics: 'SIZE'
})

causes AWS to return the following data structure:

{
  ConsumedCapacity: [{
    TableName: 'table',
    CapacityUnits: 8,
    Table: { CapacityUnits: 4 },
    GlobalSecondaryIndexes: { index: { CapacityUnits: 4 } }
  }]
}

which is then transformed by reduceCapacity inside sendAll to this:

{
  ConsumedCapacity: {
    TableName: undefined
  }
}

This PR fixes that problem.

AlexanderBelokon commented 2 years ago

Noticed that there were a few more fields missing from the current doc:

Items: Array<Map<Map>>
    Count: Integer
    ScannedCount: Integer
    LastEvaluatedKey: Map<Map>
    ConsumedCapacity: Map
        TableName: String
        CapacityUnits: Float
        ReadCapacityUnits: Float
        WriteCapacityUnits: Float
        Table: map
            ReadCapacityUnits: Float
            WriteCapacityUnits: Float
            CapacityUnits: Float
        LocalSecondaryIndexes: Map<Map>
            ReadCapacityUnits: Float
            WriteCapacityUnits: Float
            CapacityUnits: Float
        GlobalSecondaryIndexes: Map<Map>
            ReadCapacityUnits: Float
            WriteCapacityUnits: Float
            CapacityUnits: Float