UNPKG

mute-structs

Version:

NodeJS module providing an implementation of the LogootSplit CRDT algorithm

136 lines (135 loc) 4.94 kB
import { Dot } from "./dot"; import { IdentifierTuple } from "./identifiertuple"; import { Ordering } from "./ordering"; export declare class Identifier { static fromPlain(o: unknown): Identifier | null; /** * Generate a new Identifier with the same base as the provided one but with a different offset * * @param {Identifier} id The identifier to partly copy * @param {number} offset The last offset of the new Identifier * @return {IdentifierTuple} The generated Identifier */ static fromBase(id: Identifier, offset: number): Identifier; readonly tuples: IdentifierTuple[]; constructor(tuples: IdentifierTuple[]); /** * @return replica which generated this identifier. */ readonly generator: number; /** * Shortcut to retrieve the length of the Identifier * * @return {number} The length */ readonly length: number; readonly replicaNumber: number; readonly clock: number; readonly dot: Dot; /** * Retrieve the offset of the last tuple of the identifier * * @return {number} The offset */ readonly lastOffset: number; readonly base: number[]; /** * Retrieve the longest common prefix shared by this identifier with another one * * @param {Identifier} other The other identifier * @return {IdentifierTuple[]} The longest common prefix */ longestCommonPrefix(other: Identifier): IdentifierTuple[]; /** * Retrieve the longest common base shared by this identifier with another one * * @param {Identifier} other The other identifier * @return {IdentifierTuple[]} The longest common base */ longestCommonBase(other: Identifier): IdentifierTuple[]; /** * Check if this identifier is a prefix of another one * * @param {Identifier} other The other identifier * @return {boolean} Is this identifier a prefix of other */ isPrefix(other: Identifier): boolean; /** * Check if the base of this identifier is a prefix of the other one * * @param {Identifier} other The other identifier * @return {boolean} Is this base a prefix of the other one */ isBasePrefix(other: Identifier): boolean; /** * Compute the common prefix between this identifier and the other one * and return its length * * @param other The other identifier * @return {number} The length of the common prefix */ commonPrefixLength(other: Identifier): number; equals(other: Identifier): boolean; /** * Check if two identifiers share the same base * Two identifiers share the same base if only the offset * of the last tuple of each identifier differs. * * @param {Identifier} other The other identifier * @return {boolean} Are the bases equals */ equalsBase(other: Identifier): boolean; /** * Compare this identifier to another one to order them * Ordering.Less means that this is less than other * Ordering.Greater means that this is greater than other * Ordering.Equal means that this is equal to other * * @param {Identifier} other The identifier to compare * @return {Ordering} The order of the two identifier */ compareTo(other: Identifier): Ordering; /** * Check if we can generate new identifiers using * the same base as this without overflowing * * @param {number} length The number of characters we want to add * @return {boolean} */ hasPlaceAfter(length: number): boolean; /** * Check if we can generate new identifiers using * the same base as this without underflowing * * @param {number} length The number of characters we want to add * @return {boolean} */ hasPlaceBefore(length: number): boolean; /** * Compute the offset of the last identifier we can generate using * the same base as this without overflowing on next * * @param {Identifier} next The next identifier * @param {number} max The desired offset * @return {number} The actual offset we can use */ maxOffsetBeforeNext(next: Identifier, max: number): number; /** * Compute the offset of the last identifier we can generate using * the same base as this without underflowing on prev * * @param {Identifier} prev The previous identifier * @param {number} min The desired offset * @return {number} The actual offset we can use */ minOffsetAfterPrev(prev: Identifier, min: number): number; /** * Generate a new identifier by concatening another identifier to the current one. * @param {Identifier} id The identifier to concatenate * @returns {Identifier} The resulting identifier, this + id */ concat(id: Identifier): Identifier; getTail(index: number): Identifier; digest(): number; toString(): string; }