UNPKG

@splitsoftware/splitio-commons

Version:
49 lines (48 loc) 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ImpressionsCachePluggable = void 0; var utils_1 = require("../utils"); var ImpressionsCachePluggable = /** @class */ (function () { function ImpressionsCachePluggable(log, key, wrapper, metadata) { this.log = log; this.key = key; this.wrapper = wrapper; this.metadata = metadata; } /** * Push given impressions to the storage. * @param impressions - List of impresions to push. * @returns A promise that is resolved if the push operation succeeded * or rejected if the wrapper operation fails. */ ImpressionsCachePluggable.prototype.track = function (impressions) { return this.wrapper.pushItems(this.key, (0, utils_1.impressionsToJSON)(impressions, this.metadata)); }; /** * Returns a promise that resolves with the count of stored impressions, or 0 if there was some error. * The promise will never be rejected. */ ImpressionsCachePluggable.prototype.count = function () { return this.wrapper.getItemsCount(this.key).catch(function () { return 0; }); }; /** * Removes the given number of impressions from the store. If a number is not provided, it deletes all items. * The returned promise rejects if the wrapper operation fails. */ ImpressionsCachePluggable.prototype.drop = function (count) { if (!count) return this.wrapper.del(this.key); return this.wrapper.popItems(this.key, count).then(function () { }); }; /** * Pop the given number of impressions from the store. * The returned promise rejects if the wrapper operation fails. */ ImpressionsCachePluggable.prototype.popNWithMetadata = function (count) { return this.wrapper.popItems(this.key, count).then(function (items) { return items.map(function (item) { return JSON.parse(item); }); }); }; return ImpressionsCachePluggable; }()); exports.ImpressionsCachePluggable = ImpressionsCachePluggable;