import { IAugmentedObjectManager, VersionDot, IElement, VersionVector } from './common'; import { Element } from './element'; import PackedBuffer from '../thunk/packed'; import Timestamp from '../thunk/tstamp'; /** * Process-wide creator of monotonically-increasing timestamps, so they differ even with different * replicas on the same server. */ export declare const GLOBAL_TIMESTAMPER: Timestamp; /** * Meta-functions describing an augmented type, when it should apply, how it serializes. */ export interface AugmentedType { /** * Small numeric type for use with packed serialization. */ readonly name: string; /** * Returns `true` if the given native value can be given as `set()` or created from native. */ isNativeTypeCompatible(x: unknown): x is Native; /** * Creates one of these elements, given the serialized data */ createFromExisting(mgr: AugmentedObjectManager, ser: PackedBuffer | E): E; /** * If the given native JavaScript type is compatible with this Element, create and return an element with this data, * otherwise return `undefined`. */ createFromNative(mgr: AugmentedObjectManager, x: Native): E | undefined; } /** * Like the public `toElement()`, but returns the actual Element base-class, not the public interface. */ export declare function asElement(x: unknown): Element | null; /** * If the given object is an Element, returns it; if it's a native JavaScript object that is attached to an Element, * returns that Element. Otherwise returns `null`. */ export declare function toElement(x: unknown): IElement | null; export default class AugmentedObjectManager implements IAugmentedObjectManager { readonly replicaId: string; setEqualIsModification: boolean; private readonly typeRegistry; constructor(replicaId: string); createDot(): VersionDot; createVV(): VersionVector; createTimestamp(): number; /** * Called when we synchronize with another timestamp, to ensure the local clock stays ahead, according * to the Logical Time specification (see documentation). */ ensureTimestampIsLater(t: number): void; registerType(type: AugmentedType): void; serialize(x: unknown): Uint8Array; unserialize(serialized: Uint8Array): any; unserializeToElement(serialized: Uint8Array): Element; unserializeFromPackedBuffer(buf: PackedBuffer): Element; clone(x: T): T; /** * Clones an element to another element, with serialization but more efficient than just calling serialize/unserialize. */ cloneElement(el: T): T; /** * Creates the correct Element type for the given input, or throws error if the type is unsupported. */ createElement(x: unknown): Element; createObject(init?: T): T; createArray(init?: T[]): T[]; /** * Merges the state of two elements. Returns the resulting Element, which is either `dst` or `src`, possibly modified. * * We assume we can dismantel or steal the source object. If this is not a good assumption, the caller should clone it first. * * @param dst element to update in-place with `src`, unless types mis-match * @param src element whose state should be sent into `dst` * @returns `dst` if synchronization into `dst` was successful, otherwise `src`. This happens when two objects of different types are given; in that case, synchronization is not possible, so the system deterministically selects one to "win." If that one is `src`, it will be returned, and `dst` will not have been altered. */ synchronizeElements(dst: E, src: E): E; } /** * 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. */ export declare function clone(x: T): T; /** * Merges the state from `src` into `dst`. * * If `dst` is a non-augmented object, then its content is replaced with `src`, whether or not `src` is augmented. * If `dst` is augmented and `src` is regular, then the state of `dst` is completely replaced by `src`. * If `dst` is augmented and `src` is also augmented, then they are synchronized. See documentation for those details. * If either `dst` or `src` are not object-like things, it throws `TypeError`. * * @param dst regular or augmented object updated in-place with the state from `src` * @param src regular or augmented object that contains state to send into `dst` * @returns `dst` if synchronization into `dst` was successful, otherwise it can be `src`. This happens when two objects of different types are given; in that case, synchronization is not possible, so the system deterministically selects one to "win." If that one is `src`, it will be returned, and `dst` will not have been altered. */ export declare function synchronize(dst: T, src: T): T;