Skip to content

Commit 775211e

Browse files
fix(batchRequest): implement the fullResponse method on batch request
1 parent 8d144ff commit 775211e

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// tslint:disable-next-line:interface-over-type-literal
2+
import { BatchGetRequestMap, ConsumedCapacityMultiple } from 'aws-sdk/clients/dynamodb'
3+
import { BatchGetResponse } from './batch-get.response'
4+
5+
export interface BatchGetFullResponse {
6+
/**
7+
* A map of table name to a list of items. Each object in Responses consists of a table name, along with a map of attribute data consisting of the data type and attribute value.
8+
*/
9+
Responses?: BatchGetResponse
10+
/**
11+
* A map of tables and their respective keys that were not processed with the current response. The UnprocessedKeys value is in the same form as RequestItems, so the value can be provided directly to a subsequent BatchGetItem operation. For more information, see RequestItems in the Request Parameters section. Each element consists of: Keys - An array of primary key attribute values that define specific items in the table. ProjectionExpression - One or more attributes to be retrieved from the table or index. By default, all attributes are returned. If a requested attribute is not found, it does not appear in the result. ConsistentRead - The consistency of a read operation. If set to true, then a strongly consistent read is used; otherwise, an eventually consistent read is used. If there are no unprocessed keys remaining, the response contains an empty UnprocessedKeys map.
12+
*/
13+
UnprocessedKeys?: BatchGetRequestMap
14+
/**
15+
* The read capacity units consumed by the entire BatchGetItem operation. Each element consists of: TableName - The table that consumed the provisioned throughput. CapacityUnits - The total number of capacity units consumed.
16+
*/
17+
ConsumedCapacity?: ConsumedCapacityMultiple
18+
}

src/dynamo/batchget/batch-get.request.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { PrimaryKey } from '../primary-key.type'
1111
import { REGEX_TABLE_NAME } from '../request/regex'
1212
import { SessionValidityEnsurer } from '../session-validity-ensurer.type'
1313
import { TableNameResolver } from '../table-name-resolver.type'
14+
import { BatchGetFullResponse } from './batch-get-full.response'
1415
import { BatchGetResponse } from './batch-get.response'
1516

16-
// TODO add support for indexes
1717
export class BatchGetRequest {
1818
private readonly dynamoRx: DynamoRx
1919

@@ -88,7 +88,27 @@ export class BatchGetRequest {
8888
return this
8989
}
9090

91-
execFullResponse() {}
91+
execFullResponse(): Observable<BatchGetFullResponse> {
92+
return this.dynamoRx.batchGetItems(this.params).map(response => {
93+
const r = <BatchGetFullResponse>{
94+
ConsumedCapacity: response.ConsumedCapacity,
95+
UnprocessedKeys: response.UnprocessedKeys,
96+
Responses: {},
97+
}
98+
99+
if (response.Responses && Object.keys(response.Responses).length) {
100+
const responses: { [key: string]: AttributeMap } = {}
101+
Object.keys(response.Responses).forEach(tableName => {
102+
const mapped = response.Responses![tableName].map(attributeMap =>
103+
Mapper.fromDb(attributeMap, this.tables.get(tableName))
104+
)
105+
r.Responses![tableName] = mapped
106+
})
107+
}
108+
109+
return r
110+
})
111+
}
92112

93113
exec(): Observable<BatchGetResponse> {
94114
return this.dynamoRx.batchGetItems(this.params).map(response => {

0 commit comments

Comments
 (0)