UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

99 lines (98 loc) 3.41 kB
import { AbstractRga, type Chunk } from '../rga/AbstractRga'; import { type ITimestampStruct } from '../../../json-crdt-patch/clock'; import type { Model } from '../../model'; import type { JsonNode, JsonNodeView } from '..'; import type { Printable } from 'tree-dump/lib/types'; type E = ITimestampStruct; /** * @ignore * @category CRDT Node */ export declare class ArrChunk implements Chunk<E[]> { readonly id: ITimestampStruct; span: number; del: boolean; data: E[] | undefined; len: number; p: ArrChunk | undefined; l: ArrChunk | undefined; r: ArrChunk | undefined; p2: ArrChunk | undefined; l2: ArrChunk | undefined; r2: ArrChunk | undefined; s: ArrChunk | undefined; constructor(id: ITimestampStruct, span: number, data: E[] | undefined); merge(data: E[]): void; split(ticks: number): ArrChunk; delete(): void; clone(): ArrChunk; view(): E[]; } /** * Represents the `arr` JSON CRDT type, which is a Replicated Growable Array * (RGA). Each element ot the array is a reference to another JSON CRDT node. * * @category CRDT Node */ export declare class ArrNode<Element extends JsonNode = JsonNode> extends AbstractRga<E[]> implements JsonNode<JsonNodeView<Element>[]>, Printable { readonly doc: Model<any>; constructor(doc: Model<any>, id: ITimestampStruct); /** * Returns a reference to an element at a given position in the array. * * @param position The position of the element to get. * @returns An element of the array, if any. */ get(position: number): E | undefined; /** * Returns a JSON node at a given position in the array. * * @param position The position of the element to get. * @returns A JSON node, if any. */ getNode(position: number): JsonNode | undefined; /** * Returns ID of the RGA slot (not the referenced JSON node) at a given position * in the array. The ID is a timestamp the unique slot of the element in the RGA. * To retrieve the JSON node ID referenced by the slot, use {@link get} method. * * @todo Rename to `getRef`. * * @param position The position of the element to get. * @returns ID of the RGA slot. */ getId(position: number): ITimestampStruct | undefined; getById(id: ITimestampStruct): E | undefined; /** * Updates an array element in-place. Used by the "upd_arr" operation. * * @todo Verify that the new ID is greater than the old ID. * * @param ref A reference to the element slot in the array. * @param val A new value to set in the slot. * @returns The old value of the slot, if any. */ upd(ref: ITimestampStruct, val: ITimestampStruct): ITimestampStruct | undefined; /** @ignore */ createChunk(id: ITimestampStruct, data: E[] | undefined): ArrChunk; /** @ignore */ protected onChange(): void; protected toStringName(): string; /** @ignore */ child(): undefined; /** @ignore */ container(): JsonNode | undefined; /** @ignore */ private _tick; /** @ignore */ private _view; view(): JsonNodeView<Element>[]; /** @ignore */ children(callback: (node: JsonNode) => void): void; /** @ignore */ api: undefined | unknown; name(): string; /** @ignore */ protected printChunk(tab: string, chunk: ArrChunk): string; } export {};