UNPKG

mute-structs

Version:

NodeJS module providing an implementation of the LogootSplit CRDT algorithm

68 lines (64 loc) 2.83 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 (insert). */ var TextInsert = /** @class */ (function (_super) { __extends(TextInsert, _super); /** * @constructor * @param {number} offset - the insertion position in the sequence. * @param {string} content - the content to be inserted in the sequence. * @param {number} author - the author of the operation. */ function TextInsert(index, content, author) { var _this = this; console.assert(isInt32(index), "index ∈ int32"); console.assert(isInt32(author), "author ∈ int32"); _this = _super.call(this, index, author) || this; _this.content = content; return _this; } TextInsert.prototype.equals = function (other) { return this.index === other.index && this.content === other.content; }; /** * Apply the current insert operation to a LogootSplit document. * @param {LogootSDocument} doc - the LogootSplit document on which the insertion wil be performed. * @return {LogootSAdd} the logootsplit insertion that is related to the insertion that has been performed. */ TextInsert.prototype.applyTo = function (doc) { return doc.insertLocal(this.index, this.content); }; return TextInsert; }(TextOperation)); export { TextInsert }; //# sourceMappingURL=textinsert.js.map