Skip to content

Possibility to add revision to operations #11

Open
@rkusa

Description

@rkusa

tl;dr I propose to add some special optional property to operations that indicate some kind of unique identifier or version/revision.

One scenario, where JSONPatch is really useful compared to working with complete states, are apps with collaborative functionalities.

Think of a collaborative application that is distributed through multiple servers, i.e., there are is no total order for incoming changes. For concurrent changes, one operation has to win against another and the result must be the same on every server.

That is, some operations need some kind of metadata. Taking for example the replace op. When implementing a map of data as a CRDT, one approach of doing so, is to track a version number for each property. This version number has to be included in the JSONPatch operation, e.g.:

{ "op": "replace", "path": "/foo", "value": "bar", "rev": 42 }

Another example is a OR-Set, which is, simply put, a list where (internally) each item has a unique id. A scenario where this is useful:

User A adds "foobar" (gets the unique id 123) to the list. Meanwhile another user, User B, also adds "foobar" (gets the unique id 456). However, User A immediately deletes its "foobar". This remove operation should not remove the "foobar" added by User B. In case of the OR-Set, User A removes "foobar" with the id 123 and therefore "foobar" with the id 456 is not affected.

I am currently solving this by creating operations as follows:

{ "op": "add", "path": "/list/123", "value": "foobar" }
{ "op": "remove", "path": "/list/123", "value": "foobar" }

However, without knowing that the underlying data structure of the list is a or-set an we are not working with an object, these operations are easy to get wrong.

I would propose to add some special optional property to operations that indicate some kind of unique identifier or version/revision.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions