module import * as DynamoDB from 'aws-sdk/clients/dynamodb' ; import { promiseDelay } from '../../helper/promise-delay.function' ; import { DynamoDbWrapper } from '../dynamo-db-wrapper' ; param dynamoDBWrapper param params param backoffTimer param throttleTimeSlot hidden export function batchWriteItemsWriteAll ( dynamoDBWrapper , params , backoffTimer , throttleTimeSlot ) { return dynamoDBWrapper . batchWriteItem ( params ) . then ( ( response ) => { if ( hasUnprocessedItems ( response ) ) { return ( Promise . resolve ( response . UnprocessedItems ) . then ( promiseDelay ( backoffTimer . next ( ) . value * throttleTimeSlot ) ) . then ( ( unprocessedKeys ) => { const nextParams = { ... params , RequestItems : unprocessedKeys } ; return batchWriteItemsWriteAll ( dynamoDBWrapper , nextParams , backoffTimer , throttleTimeSlot ) ; } ) ) ; } return response ; } ) ; } hidden export type BatchWriteItemOutputWithUnprocessedItems = DynamoDB . BatchWriteItemOutput & { UnprocessedItems : DynamoDB . BatchWriteItemRequestMap ; } ; hidden export function hasUnprocessedItems ( response ) { if ( ! response . UnprocessedItems ) { return false ; } return Object . values ( response . UnprocessedItems ) . some ( ( t ) => ! ! t && t . length > 0 ) ; }