kuzzle-sdk
Version:
Official Javascript SDK for Kuzzle
45 lines • 1.49 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.BatchBuffer = void 0;
const InstrumentablePromise_1 = require("../InstrumentablePromise");
/**
* @internal
*/
class BatchBuffer {
constructor() {
this.indexes = new Map();
}
/**
* Add a document to the buffer of a specific collection
*
* @param index Index name
* @param collection Collection name
* @param body Document content
* @param _id Document ID
* @param options Option object passed to the m* action
*
* @returns An object containing the result index in the array of results and a promise resolving to the array of results
*/
add(index, collection, body, _id, options) {
if (!this.indexes.has(index)) {
this.indexes.set(index, new Map());
}
if (!this.indexes.get(index).has(collection)) {
this.indexes.get(index).set(collection, {
documents: [],
options,
promise: new InstrumentablePromise_1.InstrumentablePromise(),
});
}
const buffer = this.indexes.get(index).get(collection);
const idx = buffer.documents.length;
buffer.options = { ...buffer.options, ...options };
buffer.documents.push({ _id, body });
return {
idx,
promise: buffer.promise,
};
}
}
exports.BatchBuffer = BatchBuffer;
//# sourceMappingURL=BatchBuffer.js.map
;