mute-structs
Version:
NodeJS module providing an implementation of the LogootSplit CRDT algorithm
80 lines (76 loc) • 3.17 kB
JavaScript
/*
This file is part of MUTE-structs.
Copyright (C) 2017 Matthieu Nicolas, Victorien Elvinger
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
import { isArrayFromMap, isObject } from "../data-validation";
import { RenamingMap } from "./renamingmap";
var RenamingMapStore = /** @class */ (function () {
function RenamingMapStore() {
this.renamingMaps = new Map();
}
RenamingMapStore.fromPlain = function (o) {
if (isObject(o) &&
Array.isArray(o.renamingMaps)) {
var renamingMaps = o.renamingMaps
.filter(isArrayFromMap)
.map(function (_a) {
var _b = __read(_a, 2), k = _b[0], v = _b[1];
return [k, RenamingMap.fromPlain(v)];
})
.filter(function (arg) { return typeof arg[0] === "string" && arg[1] !== null; });
if (o.renamingMaps.length === renamingMaps.length) {
var renamingMapStore_1 = new RenamingMapStore();
renamingMaps.forEach(function (_a) {
var _b = __read(_a, 2), epochId = _b[0], renamingMap = _b[1];
renamingMapStore_1.internalAdd(epochId, renamingMap);
});
return renamingMapStore_1;
}
}
return null;
};
RenamingMapStore.prototype.add = function (epoch, renamingMap) {
this.internalAdd(epoch.id.asStr, renamingMap);
};
RenamingMapStore.prototype.getRenamingMap = function (epochId) {
return this.renamingMaps.get(epochId.asStr);
};
RenamingMapStore.prototype.toJSON = function () {
return { renamingMaps: Array.from(this.renamingMaps) };
};
RenamingMapStore.prototype.purge = function () {
this.renamingMaps.clear();
};
RenamingMapStore.prototype.internalAdd = function (epochId, renamingMap) {
this.renamingMaps.set(epochId, renamingMap);
};
return RenamingMapStore;
}());
export { RenamingMapStore };
//# sourceMappingURL=renamingmapstore.js.map