mute-structs
Version:
NodeJS module providing an implementation of the LogootSplit CRDT algorithm
59 lines (55 loc) • 2.48 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/>.
*/
import { isObject } from "../data-validation";
import { EpochId } from "./epochid";
var Epoch = /** @class */ (function () {
function Epoch(id, parentId) {
console.assert((id.epochNumber !== 0 && parentId !== undefined)
|| (id.epochNumber === 0 && parentId === undefined), "Every epoch, except the 0 one, should have a parentId");
this.id = id;
this.parentId = parentId;
}
Epoch.fromPlain = function (o) {
if (isObject(o)) {
var id = EpochId.fromPlain(o.id);
var parentId = EpochId.fromPlain(o.parentId);
if (id !== null && id.epochNumber === 0 && parentId === null) {
return new Epoch(id);
}
else if (id !== null && id.epochNumber !== 0 && parentId !== null) {
return new Epoch(id, parentId);
}
}
return null;
};
/**
* Check if two instances of epochs are equal
*
* @param {Epoch} other The other epoch to which to compare
* @return {boolean} Are the two epochs equal
*/
Epoch.prototype.equals = function (other) {
var areParentsEqual = (this.parentId === undefined && other.parentId === undefined) ||
(this.parentId !== undefined && other.parentId !== undefined &&
this.parentId.replicaNumber === other.parentId.replicaNumber &&
this.parentId.epochNumber === other.parentId.epochNumber);
return areParentsEqual &&
this.id.replicaNumber === other.id.replicaNumber &&
this.id.epochNumber === other.id.epochNumber;
};
return Epoch;
}());
export { Epoch };
//# sourceMappingURL=epoch.js.map