@@ -146,7 +146,7 @@ export async function getTableRow<R>(
146
146
TableName : GetItemInput [ 'TableName' ] ,
147
147
keys : { [ x : string ] : any } ,
148
148
params ?: Omit < GetItemInput , 'TableName' | 'Key' > & { projection ?: string [ ] } ,
149
- ) : Promise < ( GetItemCommandOutput & { toJs : ( ) => R | null } ) | void | null > {
149
+ ) : Promise < GetItemCommandOutput & { toJs : ( ) => R | null } > {
150
150
const { projection, ...rest } = params || { } ;
151
151
const client = getDdbClient ( ) ;
152
152
try {
@@ -161,7 +161,7 @@ export async function getTableRow<R>(
161
161
} catch ( e ) {
162
162
consoleError ( e ) ;
163
163
consoleError ( { TableName, keys, params } ) ;
164
- return null ;
164
+ throw e ;
165
165
}
166
166
}
167
167
@@ -210,11 +210,12 @@ async function batchWriteTable(
210
210
/**
211
211
* @param request
212
212
*/
213
+
213
214
function getBatchWriteRequest ( request : 'PutRequest' | 'DeleteRequest' ) {
214
- return async function < R > (
215
+ return async function < R , L extends R > (
215
216
TableName : string ,
216
- unmarshalledList : any [ ] ,
217
- predicate ?: ( item : any ) => R | undefined | Promise < R | undefined > ,
217
+ unmarshalledList : L [ ] ,
218
+ predicate ?: < L > ( item : L ) => R | undefined | Promise < R | undefined > ,
218
219
) : Promise < { results : ( BatchWriteItemCommandOutput | null ) [ ] ; actualList : R [ ] } | void > {
219
220
const results = [ ] ;
220
221
const actualList : R [ ] = [ ] ;
@@ -231,12 +232,12 @@ function getBatchWriteRequest(request: 'PutRequest' | 'DeleteRequest') {
231
232
const requests : WriteRequest [ ] = [ ] ;
232
233
for ( const item of chunk ) {
233
234
try {
234
- let row = item ;
235
+ let row : R = item as unknown as R ;
235
236
if ( predicate ) {
236
237
if ( predicate . constructor . name === 'AsyncFunction' ) {
237
238
row = await ( predicate ( item ) as Promise < R > ) ;
238
239
} else {
239
- row = predicate ( item ) ;
240
+ row = predicate ( item ) as R ;
240
241
}
241
242
}
242
243
// skip to next if row is falsey
@@ -456,7 +457,7 @@ async function handleQueryCommand<R>(query: QueryCommandInput) {
456
457
} catch ( e ) {
457
458
consoleError ( e ) ;
458
459
consoleError ( { query } ) ;
459
- return null ;
460
+ throw e ;
460
461
}
461
462
}
462
463
@@ -524,7 +525,7 @@ export async function updateTableRow<R>(
524
525
ConditionExpression ?: string ;
525
526
} ,
526
527
ReturnValues = 'ALL_NEW' ,
527
- ) : Promise < ( UpdateItemCommandOutput & { toJs : ( predicate ?: ( row : R ) => R ) => R } ) | null > {
528
+ ) : Promise < UpdateItemCommandOutput & { toJs : ( iterator ?: ( row : R ) => R ) => R } > {
528
529
const { UpdateExpression, expressionAttributeValues, ExpressionAttributeNames } = params ;
529
530
const client = getDdbClient ( ) ;
530
531
try {
@@ -541,9 +542,9 @@ export async function updateTableRow<R>(
541
542
const result = await client . send ( new UpdateItemCommand ( query ) ) ;
542
543
return {
543
544
...result ,
544
- toJs : ( predicate ) => {
545
+ toJs : ( iterator ) => {
545
546
const item = ( result . Attributes ? unmarshall ( result . Attributes ) : { } ) as R ;
546
- return predicate ? predicate ( item ) : item ;
547
+ return iterator ? iterator ( item ) : item ;
547
548
} ,
548
549
} ;
549
550
} catch ( e ) {
0 commit comments