import { VersionVector, IElement, IElementCollection, NotifyChangeType } from './common'; import AugmentedObjectManager, { AugmentedType } from './manager'; import { ObjectElement } from './object'; import PackedBuffer from '../thunk/packed'; /** * An element inside an augmented object or array, which can be accessed, changed, hooked, uniquely identified, etc.. */ export declare abstract class Element implements IElement { /** * Creation VV. Is a dot when an object is first created, but can be a VV if multiple replicas create * the same object in a collection. */ readonly cr: VersionVector; /** * Parent Collection object that we are attached to, or `null` if this is a root. */ parent: CollectionElement | null; /** * Replica manager, with utilities that aren't available in the public API. * * @type {AugmentedObjectManager} * @memberof Element */ mgr: AugmentedObjectManager; constructor(mgr: AugmentedObjectManager, ser?: PackedBuffer | Element); /** * Appends our internal state to an array of buffers for serialization. */ toPackedBuffer(buf: PackedBuffer): void; toStateString(depth?: number): string; protected toStateStringElement(): string; /** * Returns a human-readable string including the underlying structure. */ toString(): string; /** * Gets the native JavaScript value, such as a scalar type, a plain object, or one of our specifically-supported classes. */ abstract valueOf(): any; /** * Resets the manager for this element and all children. */ setManager(mgr: AugmentedObjectManager): void; /** * Gets the boolean-type value, or an interpretation of the value as "truthy" or "falsey," * where `null`, `0`, `""` are false, and everything else is true. * * @type {boolean} * @memberof Element */ get boolean(): boolean; /** * Gets the number-typed value, or `Number.NaN` if the data type is not a number. * * @type {number} * @memberof Element */ get number(): number; /** * Gets the string-type value, or a string representation of the value if it's not a string. * * @type {string} * @memberof Element */ abstract get string(): string; /** * Gets the object-type value, or null if it is not an object. * * @type {AugmentedObject} * @memberof Element */ get object(): ObjectElement | null; /** * Sets the value to the given value, but only if the types are compatible or can be coersced. * If successful, returns `true`, else returns `false`. If the value isn't different, the state * is not updated, but this still returns `true`. */ abstract set(x: unknown): boolean; /** * Globally-unique ID set upon creation. Sometimes an Element's ID can change when the underlying * data changes, for example if the type of the `value` changes, or if the Element is deleted * and re-added to an object or array. But normally the ID remains the same when the value changes. * * @readonly * @type {string} * @memberof Element */ get guid(): string; /** * Gets the SHA256 of the state of this element, not just the data type but the internal state * that is used for synchronization. * * @readonly * @type {string} * @memberof Element */ get sha256(): string; /** * The modification version vector of this object. * For scalars this is a modification dot; for collections this is their obsertion vector. */ abstract get modificationVV(): VersionVector; /** * Called by subclasses when an element is updated. */ notifyChanged(type: NotifyChangeType, changed: Element): void; /** * Gets the type that's registered to this Element class. * * @readonly * @type {AugmentedType} * @memberof Element */ abstract get type(): AugmentedType; get typeName(): string; /** * Synchronizes with another element of the same type. */ abstract synchronize(src: this): void; } /** * An element representing a number of other elements, such as an object, array, set. */ export declare abstract class CollectionElement extends Element implements IElementCollection { /** * "Observed" Version Vector: What changes in all children we've witnessed, used to manage * deletions without tombstones, create OR-behavior for add/delete, and to request only * newer changes over a network, and to efficiently update when there are no local changes to merge. */ readonly obs: VersionVector; constructor(mgr: AugmentedObjectManager, ser?: PackedBuffer | CollectionElement); toPackedBuffer(buf: PackedBuffer): void; /** * Number of items in the collection. This should not count things like deletion tombstones; this is the logical number of living elements. */ abstract get size(): number; /** * Actual number of items in the collection, which might include things like tombstones or array-holes. */ get fullSize(): number; /** * Gets the list of child elements, in any order. */ abstract get children(): Iterable; /** * Update the observation VV. */ touch(type: NotifyChangeType): void; get modificationVV(): VersionVector; notifyChanged(type: NotifyChangeType, changed: Element): void; setManager(mgr: AugmentedObjectManager): void; }