import * as VV from '@asmartbear/version-vectors'; /** * A native JavaScript scalar type. */ export declare type Scalar = null | boolean | number | string; /** * Plain Old JavaScript Object -- the type of object we support. * Basically the type that naturally unserializes through `JSON.parse()`. */ export declare type POJO = Scalar | Array | { [field: string]: POJO; }; /** * The type of version vector we use, where the timestamps are strings. */ export declare type VersionVector = VV.VV; /** * The type of version vector dot we use, where the timestamps are strings. */ export declare type VersionDot = VV.Dot; /** * Use this faux property on a POJO to identify it as augmented, and the value is the underlying Element. */ export declare const SYMBOL_ELEMENT: unique symbol; /** * An instance that provides the management functionality of augmented objects, such as creating new ones, * synchronizing, serializing, and cloning. * * By placing these in an interface, not only can the implementation be extended by other libraries, but also * we can attach "global" state such as Replica ID to the data inside augmented objects. */ export interface IAugmentedObjectManager { /** * Globally-unique ID. The ID will remain stable over time, if a local storage system is configured. */ readonly replicaId: string; /** * If true, consider setting a value equal to itself to still be a modification with regard to synchronization, * otherwise setting a leaf element to an unchanged value is completely ignored. */ setEqualIsModification: boolean; /** * Creates an augmented object, which acts exactly like a plain JavaScript object. */ createObject(init?: T): T; /** * Creates an augmented array, which acts exactly like a plain JavaScript array. */ createArray(init?: T[]): T[]; /** * Serialize an augmented object into a compact byte-buffer, or throws error if it's not an augmented object. */ serialize(x: unknown): Uint8Array; /** * Unserialize an augmented object from a previous call to `serialize()`. Throws error if bytes are incorrect. */ unserialize(serialized: Uint8Array): any; /** * Like `unserialize()`, but returns the underlying `IElement` instead of the augmented JavaScript object. */ unserializeToElement(serialized: Uint8Array): IElement; /** * Clones an augmented object, retaining the synchronization data that allows it to re-synchronize with * another version, another time. If the given object isn't augmented, still executes a deep-clone. */ clone(x: T): T; /** * Same as `createDot()`, but returns as a single-element version vector instead of a dot. */ createVV(): VersionVector; /** * Creates a new replica/timestamp version dot. */ createDot(): VersionDot; /** * Creates a new timestamp value, as with creation dots and vectors. */ createTimestamp(): number; } export declare enum NotifyChangeType { /** * No change, just updated synchronization data */ Touch = 0, /** * Change came from a synchronization, intrinsic to the augmented system, rather than the local replica */ Sync = 1, /** * Change came from an object on the local replica. */ Local = 2 } /** * A piece of Augmented data, whether scalar or structured, which is automatically synchronized. */ export interface IElement { /** * The name of the Augmented data-type. * * @readonly */ readonly typeName: string; /** * Creation Version Vector. Is a dot when an object is first created, but can be a VV if multiple replicas * independentantly the same object in a collection. */ readonly cr: VersionVector; /** * Parent Element that we are attached to, or `null` if this is a root. This can change over time. */ parent: IElementCollection | null; /** * The modification version vector of this object. * For scalars this is a modification dot; for collections this is their obsertion vector. */ modificationVV: VersionVector; /** * The object manager used to create the local instance of this object. */ mgr: IAugmentedObjectManager; /** * 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. */ valueOf(): any; /** * 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} */ boolean: boolean; /** * Gets the number-typed value, or `Number.NaN` if the data type is not a number. * * @type {number} */ number: number; /** * Gets the string-type value, or a string representation of the value if it's not a string. * * @type {string} * @memberof Element */ string: string; /** * Sets the element's 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`. */ 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 */ 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 */ sha256: string; /** * Generates a human-readable string specifying the internal state of the element, for debugging. * * @depth the indention level */ toStateString(depth?: number): string; } /** * An Element representing a collection of other elements, such as an object, array, set, map, or specific structured data. */ export interface IElementCollection extends IElement { /** * Rweturns the number of items in the collection. */ size: number; /** * Gets the list of child elements. In some collections this is an arbitrary order (e.g. map), in others the * order is defined (e.g. array). */ children: Iterable; } /** * Returns true if x is a `Scalar` type, and asserts it with Typescript. */ export declare function isScalar(x: unknown): x is Scalar; /** * Returns true if x is a `Plain Object,` meaning one we can naturally iterate and convert into our object-map. */ export declare function isPlainObject(x: unknown): x is object; /** * Returns true if x is a `POJO,` meaning it will serialize/unserialize via JSON into the same thing. */ export declare function isPojo(x: unknown): x is POJO; /** * Returns a brief string highlighting a version vector but cut short for the purpose of light viewing, not accuracy. */ export declare function toBriefVersionVectorString(v: VersionVector): string; /** * Converts all objects to strings useful as objects, either because they are already strings or something that * converts easily to strings (like numbers), or we hash the thing into a string. */ export declare function toStringKey(x: unknown): string;