mute-structs
Version:
NodeJS module providing an implementation of the LogootSplit CRDT algorithm
82 lines (78 loc) • 3.49 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 __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var data_validation_1 = require("../../data-validation");
var epoch_1 = require("../../epoch/epoch");
var identifierinterval_1 = require("../../identifierinterval");
var int32_1 = require("../../int32");
var renamablelistoperation_1 = require("../renamablelistoperation");
/**
* Represents a LogootSplit rename operation.
*/
var LogootSRename = /** @class */ (function (_super) {
__extends(LogootSRename, _super);
/**
* @constructor
*/
function LogootSRename(replicaNumber, clock, epoch, renamedIdIntervals) {
var _this = _super.call(this, epoch) || this;
_this.replicaNumber = replicaNumber;
_this.clock = clock;
_this.renamedIdIntervals = renamedIdIntervals;
return _this;
}
LogootSRename.fromPlain = function (o) {
if (data_validation_1.isObject(o) &&
int32_1.isInt32(o.replicaNumber) && int32_1.isInt32(o.clock) &&
Array.isArray(o.renamedIdIntervals) && o.renamedIdIntervals.length > 0) {
var renamedIdIntervals = o.renamedIdIntervals.map(identifierinterval_1.IdentifierInterval.fromPlain)
.filter(function (v) { return v !== null; });
var epoch = epoch_1.Epoch.fromPlain(o.epoch);
if (epoch !== null &&
o.renamedIdIntervals.length === renamedIdIntervals.length) {
return new LogootSRename(o.replicaNumber, o.clock, epoch, renamedIdIntervals);
}
}
return null;
};
Object.defineProperty(LogootSRename.prototype, "author", {
get: function () {
return this.replicaNumber;
},
enumerable: true,
configurable: true
});
LogootSRename.prototype.execute = function (renamableList) {
renamableList.renameRemote(this.replicaNumber, this.clock, this.epoch, this.renamedIdIntervals);
return [];
};
return LogootSRename;
}(renamablelistoperation_1.RenamableListOperation));
exports.LogootSRename = LogootSRename;
//# sourceMappingURL=logootsrename.js.map