ottypes / json0

Version 0 of the JSON OT type
447 stars 64 forks source link

✨ Add presence support #48

Open alecgibson opened 2 years ago

alecgibson commented 2 years ago

Fixes https://github.com/ottypes/json0/issues/30

This change adds support for the transformPresence() method that sharedb uses.

We add support for both text0 and json0.

text0

The text0 implementation leans on the existing transformPosition, and takes its form and tests from rich-text.

Its shape takes the form:

{
  index: 3,
  length: 5,
}

Where:

json0

The json0 implementation has limited functionality because of the limitations of the json0 type itself: we handle list moves lm, but cannot infer any information when moving objects around the tree, because the oi and od operations are destructive.

However, it will attempt to transform embedded subtypes that support presence.

Its shape takes the form:

{
  p: ['key', 123],
  v: {},
}

Where:

The presence value v can take any arbitrary value (in simple cases it may even be omitted entirely).

The exception to this is when using subtypes, where v should take the presence shape defined by the subtype. For example, when using text0:

{
  p: ['key'],
  v: {index: 5, length: 0},
}