import * as tslib_1 from "tslib";
import { of } from 'rxjs';
import { delay, mergeMap } from 'rxjs/operators';
export function batchWriteItemsWriteAll(dynamoRx, params, backoffTimer, throttleTimeSlot) {
    return dynamoRx.batchWriteItem(params)
        .pipe(mergeMap(function (response) {
        if (hasUnprocessedItems(response)) {
            return of(response.UnprocessedItems)
                .pipe(delay(backoffTimer.next().value * throttleTimeSlot), mergeMap(function (unprocessedKeys) {
                var nextParams = tslib_1.__assign({}, params, { RequestItems: unprocessedKeys });
                return batchWriteItemsWriteAll(dynamoRx, nextParams, backoffTimer, throttleTimeSlot);
            }));
        }
        return of(response);
    }));
}
export function hasUnprocessedItems(response) {
    if (!response.UnprocessedItems) {
        return false;
    }
    return Object.values(response.UnprocessedItems)
        .some(function (t) { return !!t && t.length > 0; });
}
//# sourceMappingURL=batch-write-utils.js.map