"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BatchLink = exports.OperationBatcher = void 0;
const core_1 = require("@apollo/client/link/core");
const batching_js_1 = require("./batching.cjs");
var batching_js_2 = require("./batching.cjs");
Object.defineProperty(exports, "OperationBatcher", { enumerable: true, get: function () { return batching_js_2.OperationBatcher; } });
class BatchLink extends core_1.ApolloLink {
    batcher;
    constructor(fetchParams) {
        super();
        const { batchDebounce, batchInterval = 10, batchMax = 0, batchHandler = () => null, batchKey = () => "", } = fetchParams || {};
        this.batcher = new batching_js_1.OperationBatcher({
            batchDebounce,
            batchInterval,
            batchMax,
            batchHandler,
            batchKey,
        });
        //make this link terminating
        if (fetchParams.batchHandler.length <= 1) {
            this.request = (operation) => this.batcher.enqueueRequest({ operation });
        }
    }
    request(operation, forward) {
        return this.batcher.enqueueRequest({
            operation,
            forward,
        });
    }
}
exports.BatchLink = BatchLink;
//# sourceMappingURL=batchLink.cjs.map
