UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

80 lines (79 loc) 2.09 kB
import { type ITimestampStruct } from '../../../json-crdt-patch/clock'; import type { Model } from '../../model'; import type { Printable } from 'tree-dump/lib/types'; import type { JsonNode, JsonNodeView } from '..'; /** * Represents a `obj` JSON CRDT node, which is a Last-write-wins (LWW) object. * It is a map of string keys to LWW registers. The value of each register is * a reference to another JSON CRDT node. * * @category CRDT Node */ export declare class ObjNode<Value extends Record<string, JsonNode> = Record<string, JsonNode>> implements JsonNode<JsonNodeView<Value>>, Printable { /** * @ignore */ protected readonly doc: Model<any>; readonly id: ITimestampStruct; /** * @ignore */ readonly keys: Map<string, ITimestampStruct>; constructor( /** * @ignore */ doc: Model<any>, id: ITimestampStruct); /** * Retrieves a JSON CRDT node at the given key. * * @param key A key of the object. * @returns JSON CRDT node at the given key, if any. */ get<K extends keyof Value>(key: K): undefined | Value[K]; /** * Rewrites object key. * * @param key Object key to set. * @param id ID of the contents of the key. * @returns Returns old entry ID, if any. * @ignore */ put(key: string, id: ITimestampStruct): undefined | ITimestampStruct; /** * Iterate over all key-value pairs in the object. * * @param callback Callback to call for each key-value pair. */ nodes(callback: (node: JsonNode, key: string) => void): void; /** * @ignore */ children(callback: (node: JsonNode) => void): void; /** * @ignore */ child(): undefined; /** * @ignore */ container(): JsonNode | undefined; /** * @ignore */ private _tick; /** * @ignore */ private _view; /** * @ignore */ view(): JsonNodeView<Value>; /** * @ignore */ api: undefined | unknown; name(): string; toString(tab?: string): string; }