UNPKG

mute-structs

Version:

NodeJS module providing an implementation of the LogootSplit CRDT algorithm

70 lines (66 loc) 2.98 kB
/* 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 __()); }; })(); import { isInt32 } from "../../int32"; import { TextOperation } from "../textoperation"; /** * Represents a sequence operation (deletion). */ var TextDelete = /** @class */ (function (_super) { __extends(TextDelete, _super); /** * @constructor * @param {number} index - the position of the first element to be deleted in the sequence. * @param {number} length - the length of the range to be deleted in the sequence. * @param {number} author - the author of the operation. */ function TextDelete(index, length, author) { var _this = this; console.assert(isInt32(index), "index ∈ int32"); console.assert(isInt32(length), "length ∈ int32"); console.assert(length > 0, "length > 0"); console.assert(isInt32(author), "author ∈ int32"); _this = _super.call(this, index, author) || this; _this.length = length; return _this; } TextDelete.prototype.equals = function (other) { return this.index === other.index && this.length === other.length; }; /** * Apply the current delete operation to a LogootSplit document. * @param {LogootSDocument} doc - the LogootSplit document on which the deletion wil be performed. * @return {LogootSDel} the logootsplit deletion that is related to the deletion that has been performed. */ TextDelete.prototype.applyTo = function (doc) { return doc.delLocal(this.index, this.index + this.length - 1); }; return TextDelete; }(TextOperation)); export { TextDelete }; //# sourceMappingURL=textdelete.js.map