UNPKG

@splitsoftware/splitio-commons

Version:
71 lines (70 loc) 2.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AttributesCacheInMemory = void 0; var objectAssign_1 = require("../../utils/lang/objectAssign"); var AttributesCacheInMemory = /** @class */ (function () { function AttributesCacheInMemory() { this.attributesCache = {}; } /** * Create or update the value for the given attribute * * @param attributeName - attribute name * @param attributeValue - attribute value * @returns the attribute was stored */ AttributesCacheInMemory.prototype.setAttribute = function (attributeName, attributeValue) { this.attributesCache[attributeName] = attributeValue; return true; }; /** * Retrieves the value of a given attribute * * @param attributeName - attribute name * @returns stored attribute value */ AttributesCacheInMemory.prototype.getAttribute = function (attributeName) { return this.attributesCache[attributeName]; }; /** * Create or update all the given attributes * * @param attributes - attributes to create or update * @returns attributes were stored */ AttributesCacheInMemory.prototype.setAttributes = function (attributes) { this.attributesCache = (0, objectAssign_1.objectAssign)(this.attributesCache, attributes); return true; }; /** * Retrieve the full attributes map * * @returns stored attributes */ AttributesCacheInMemory.prototype.getAll = function () { return this.attributesCache; }; /** * Removes a given attribute from the map * * @param attributeName - attribute to remove * @returns attribute removed */ AttributesCacheInMemory.prototype.removeAttribute = function (attributeName) { if (Object.keys(this.attributesCache).indexOf(attributeName) >= 0) { delete this.attributesCache[attributeName]; return true; } return false; }; /** * Clears all attributes stored in the SDK * */ AttributesCacheInMemory.prototype.clear = function () { this.attributesCache = {}; return true; }; return AttributesCacheInMemory; }()); exports.AttributesCacheInMemory = AttributesCacheInMemory;