Skip to content

Commit

Permalink
amend: fix batchWriteWithRetry type
Browse files Browse the repository at this point in the history
  • Loading branch information
thepont committed Apr 15, 2024
1 parent eed6994 commit fe22f2f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/92green-aws-rxjs/src/dynamodb/batchWriteWithRetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {EMPTY} from 'rxjs';
import {pipe} from 'rxjs';
import {from} from 'rxjs';
import {
map,
expand,
mergeMap,
bufferCount,
Expand All @@ -17,10 +18,17 @@ type Config = {

const MAX_BATCH_WRITE = 25;

export default function <T>(config: Config): UnaryFunction<Observable<T>, Observable<T>> {
export default function <T extends Record<string, any>>(config: Config): UnaryFunction<Observable<T>, Observable<T>> {
const {docClient, tableName} = config;

return pipe(
map((item: T) => {
return {
PutRequest: {
Item: item
}
}
}),
bufferCount(MAX_BATCH_WRITE),
mergeMap((items) => {
return from(docClient.send(new BatchWriteCommand({
Expand All @@ -41,7 +49,8 @@ export default function <T>(config: Config): UnaryFunction<Observable<T>, Observ
}),
// Wait for the observable to finish and then emit the incoming items back out
last(),
mergeMap(() => items)
mergeMap(() => items),
map((item) => item.PutRequest.Item)
);
})
);
Expand Down

0 comments on commit fe22f2f

Please sign in to comment.