UNPKG

@splitsoftware/splitio-commons

Version:
46 lines (45 loc) 1.93 kB
import { impressionsToJSON } from '../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, 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; }()); export { ImpressionsCachePluggable };