Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/automerge/next.ts

A JSON-like data structure (a CRDT) that can be modified concurrently by different users, and merged again automatically.
Latest
import * as automerge from "https://deno.land/x/automerge@2.2.2/next.ts";

The next API

This module contains new features we are working on which are backwards incompatible with the current API of Automerge. This module will become the API of the next major version of Automerge

Differences from stable

In the stable API text objects are represented using the Text class. This means you must decide up front whether your string data might need concurrent merges in the future and if you change your mind you have to figure out how to migrate your data. In the unstable API the Text class is gone and all strings are represented using the text CRDT, allowing for concurrent changes. Modifying a string is done using the splice function. You can still access the old behaviour of strings which do not support merging behaviour via the RawString class.

This leads to the following differences from stable:

  • There is no unstable.Text class, all strings are text objects
  • Reading strings in an unstable document is the same as reading any other javascript string
  • To modify strings in an unstable document use splice
  • The AutomergeValue type does not include the Text class but the RawString class is included in the ScalarValue type

CHANGELOG

  • Rename this module to next to reflect our increased confidence in it and stability commitment to it
  • Introduce this module to expose the new API which has no Text class

Classes

The most basic CRDT: an integer value that can be changed only by incrementing and decrementing. Since addition of integers is commutative, the value trivially converges.

Functions

Apply changes received from another document

Get the block marker at the given index

Update the contents of an automerge document

Make a change to the document as it was at a particular point in history

Make a full writable copy of an automerge document

Decode some binary data into a SyncState

Function for use in change which deletes values from a list at a given index

Create a set of patches representing the change from one set of heads to another

Make a change to a document which does not modify the document

encode a SyncState into binary to send over the network

Explicity free the memory backing a document. Note that this is note necessary in environments which support FinalizationRegistry

Create an automerge document from a POJO

Generate a sync message to send to the peer represented by inState

Get the actor ID associated with the document

Get all the changes in a document

Get the changes which are in newState but not in oldState. The returned changes can be loaded in oldState via applyChanges.

Get the conflicts associated with a property

Returns a cursor for the given position in a string.

Returns the current index of the cursor.

Get the hashes of the heads of this document

Get the binary representation of the last change which was made to this doc

Get any changes in doc which are not dependencies of heads

Return the object ID of an arbitrary javascript value

Create a new automerge document

Create a new, blank SyncState

Function for use in change which inserts values into a list at a given index

Delete the block marker at the given index

Load an automerge document from a compressed document produce by save

Load changes produced by saveIncremental, or partial changes

Merge remote into local

Update a document and our sync state on receiving a sync message

Export the contents of a document to a compressed format

Create binary save data to be appended to a save file or fed into loadIncremental

Return the text + block markers at a given path

Modify a string

Insert a new block marker at the given index

Update the block marker at the given index

Update the spans at the given path

Update the value of a string

Make an immutable view of an automerge document as at heads

Type Aliases

The type returned from changeAt

Function which is called by change when making changes to a Doc<T>

Options passed to change, and emptyChange

An automerge document.

Callback which is called by various methods in this library to notify the user of what changes have been made.

An opaque type tracking the state of sync with a remote peer