Represents a JSON CRDT patch.

Normally, you would create a new patch using the PatchBuilder class.

import {Patch, PatchBuilder, LogicalClock} from 'json-joy/lib/json-crdt-patch';

const clock = new LogicalClock(3, 100);
const builder = new PatchBuilder(clock);
const patch = builder.flush();

Save patch to a binary representation:

const binary = patch.toBinary();

Load patch from a binary representation:

const patch = Patch.fromBinary(binary);

Implements

  • Printable

Constructors

Properties

meta: unknown = undefined

Arbitrary metadata associated with the patch, which is not used by the library.

A list of operations in the patch.

Methods

  • The .rebase() operation is meant to work only with patch that use the server clock. When receiving a patch from a client, the starting ID of the patch can be out of sync with the server clock. For example, if some other user has in the meantime pushed operations to the server.

    The .rebase() operation returns a new Patch with the IDs recalculated such that the first operation has ID of the patch is equal to the actual server time tip.

    Parameters

    • serverTime: number

      Real server time tip (ID of the next expected operation).

    • transformHorizon: number

    Returns Patch

  • Returns the total time span of the patch, which is the sum of all operation spans.

    Returns number

    The length of the patch.

  • Marshals the patch into a binary representation.

    Returns Uint8Array

    A binary representation of the patch.

  • Returns a textual human-readable representation of the patch. This can be used for debugging purposes.

    Parameters

    • tab: string = ''

      Start string for each line.

    Returns string

    Text representation of the patch.