"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
const request_1 = require("../dynamo/request");
/**
 * When we cant load all the items of a table with one request, we will fetch as long as there is more data
 * available. This can be used with scan and query requests.
 */
function fetchAll(request, startKey) {
    request.limit(request_1.Request.INFINITE_LIMIT);
    if (startKey) {
        request.exclusiveStartKey(startKey);
    }
    return request.execFullResponse().pipe(operators_1.concatMap(response => {
        if (response.LastEvaluatedKey) {
            return fetchAll(request, response.LastEvaluatedKey).pipe(operators_1.map(innerResponse => [...response.Items, ...innerResponse]));
        }
        else {
            return rxjs_1.of(response.Items);
        }
    }));
}
exports.fetchAll = fetchAll;
//# sourceMappingURL=fetch-all.function.js.map