export function mergeConsumedCapacities()

in packages/dynamodb-query-iterator/src/mergeConsumedCapacities.ts [10:38]


export function mergeConsumedCapacities(
    a?: ConsumedCapacity,
    b?: ConsumedCapacity
): ConsumedCapacity|undefined {
    if (a || b) {
        a = a || {};
        b = b || {};

        if ((a.TableName && b.TableName) && a.TableName !== b.TableName) {
            throw new Error(
                'Consumed capacity reports may only be merged if they describe the same table'
            );
        }

        return {
            TableName: a.TableName || b.TableName,
            CapacityUnits: (a.CapacityUnits || 0) + (b.CapacityUnits || 0),
            Table: mergeCapacities(a.Table, b.Table),
            LocalSecondaryIndexes: mergeCapacityMaps(
                a.LocalSecondaryIndexes,
                b.LocalSecondaryIndexes
            ),
            GlobalSecondaryIndexes: mergeCapacityMaps(
                a.GlobalSecondaryIndexes,
                b.GlobalSecondaryIndexes
            ),
        }
    }
}