fsm-state-manager
Version:
A Flow FSM using a finite state machine pattern
50 lines (49 loc) • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CacheMemory = void 0;
var CacheMemory = /** @class */ (function () {
function CacheMemory(payloadSensetive) {
this.store = {};
this.payloadSensetiveFlag = false;
this.payloadSensetiveFlag = payloadSensetive;
}
CacheMemory.prototype.get = function (event, appliedData) {
var key = this.generateCacheKey(event, appliedData);
return this.store[key];
};
CacheMemory.prototype.set = function (event, value) {
var key = this.generateCacheKey(event, value.appliedData);
this.store[key] = value;
};
CacheMemory.prototype.has = function (event, appliedData) {
if (appliedData) {
var key = this.generateCacheKey(event, appliedData);
return this.store[key] !== undefined;
}
else {
var key = this.generateCacheKey(event, []);
return this.store[key] !== undefined;
}
};
CacheMemory.prototype.delete = function (event, payload) {
var key = this.generateCacheKey(event, payload);
delete this.store[key];
};
CacheMemory.prototype.clear = function () {
this.store = {};
};
CacheMemory.prototype.generateCacheKey = function (event, payload) {
if (!this.payloadSensetiveFlag)
return event;
try {
var encoded = JSON.stringify(payload !== null && payload !== void 0 ? payload : null);
var hash = btoa(encodeURIComponent(encoded));
return "".concat(event, "::").concat(hash);
}
catch (_a) {
return "".concat(event, "::unknown");
}
};
return CacheMemory;
}());
exports.CacheMemory = CacheMemory;