export * from "./loro_wasm"; export type * from "./loro_wasm"; import { AwarenessWasm, EphemeralStoreWasm, PeerID, Container, ContainerID, ContainerType, LoroCounter, LoroDoc, LoroList, LoroMap, LoroText, LoroTree, OpId, Value, AwarenessListener, EphemeralListener, EphemeralLocalListener } from "./loro_wasm"; /** * @deprecated Please use LoroDoc */ export declare class Loro extends LoroDoc { } export declare function isContainerId(s: string): s is ContainerID; /** Whether the value is a container. * * # Example * * ```ts * const doc = new LoroDoc(); * const map = doc.getMap("map"); * const list = doc.getList("list"); * const text = doc.getText("text"); * isContainer(map); // true * isContainer(list); // true * isContainer(text); // true * isContainer(123); // false * isContainer("123"); // false * isContainer({}); // false * ``` */ export declare function isContainer(value: any): value is Container; /** Get the type of a value that may be a container. * * # Example * * ```ts * const doc = new LoroDoc(); * const map = doc.getMap("map"); * const list = doc.getList("list"); * const text = doc.getText("text"); * getType(map); // "Map" * getType(list); // "List" * getType(text); // "Text" * getType(123); // "Json" * getType("123"); // "Json" * getType({}); // "Json" * ``` */ export declare function getType(value: T): T extends LoroText ? "Text" : T extends LoroMap ? "Map" : T extends LoroTree ? "Tree" : T extends LoroList ? "List" : T extends LoroCounter ? "Counter" : "Json"; export declare function newContainerID(id: OpId, type: ContainerType): ContainerID; export declare function newRootContainerID(name: string, type: ContainerType): ContainerID; /** * @deprecated Please use `EphemeralStore` instead. * * Awareness is a structure that allows to track the ephemeral state of the peers. * * If we don't receive a state update from a peer within the timeout, we will remove their state. * The timeout is in milliseconds. This can be used to handle the offline state of a peer. */ export declare class Awareness { inner: AwarenessWasm; private peer; private timer; private timeout; private listeners; constructor(peer: PeerID, timeout?: number); apply(bytes: Uint8Array, origin?: string): void; setLocalState(state: T): void; getLocalState(): T | undefined; getAllStates(): Record; encode(peers: PeerID[]): Uint8Array; encodeAll(): Uint8Array; addListener(listener: AwarenessListener): void; removeListener(listener: AwarenessListener): void; peers(): PeerID[]; destroy(): void; private startTimerIfNotEmpty; } /** * EphemeralStore is a structure that allows to track the ephemeral state of the peers. * * It can be used to synchronize cursor positions, selections, and the names of the peers. * Each entry uses timestamp-based LWW (Last-Write-Wins) for conflict resolution. * * If we don't receive a state update from a peer within the timeout, we will remove their state. * The timeout is in milliseconds. This can be used to handle the offline state of a peer. * * @example * * ```ts * const store = new EphemeralStore(); * const store2 = new EphemeralStore(); * // Subscribe to local updates * store.subscribeLocalUpdates((data)=>{ * store2.apply(data); * }) * // Subscribe to all updates * store2.subscribe((event)=>{ * console.log("event: ", event); * }) * // Set a value * store.set("key", "value"); * // Encode the value * const encoded = store.encode("key"); * // Apply the encoded value * store2.apply(encoded); * ``` */ export declare class EphemeralStore = Record> { inner: EphemeralStoreWasm; private timer; private timeout; constructor(timeout?: number); apply(bytes: Uint8Array): void; set(key: K, value: T[K]): void; delete(key: K): void; get(key: K): T[K] | undefined; getAllStates(): Partial; encode(key: K): Uint8Array; encodeAll(): Uint8Array; keys(): string[]; destroy(): void; subscribe(listener: EphemeralListener): () => void; subscribeLocalUpdates(listener: EphemeralLocalListener): () => void; private startTimerIfNotEmpty; } export declare function idStrToId(idStr: `${number}@${PeerID}`): OpId;