share / share/sharedb

ottypes/docs spec is not supported correctly wrt (de)serialisation

Open
#214 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
6.5k
Forks
456
Avg merge
1d 5h
Merged PRs (30d)
5

Description

Spec: https://github.com/ottypes/docs#standard-properties

First of all, according to the spec, initialData, snapshot and data may all be completely different data types in the following function specs create([initialData]) -> snapshot, serialize(snapshot) -> data, deserialize(data) -> snapshot. text-tp2 is an example of such a type. Please note also that create([initialData]) -> snapshot returns a non-serialized snapshot.

Secondly, apply(snapshot, op) -> snapshot' expects a non-serialized snapshot as the first parameter. Again, text-tp2 is an example of a type which relies on the first param being a non-serialized snapshot.

I found a number of problems in ShareDB related to the above:

  1. ShareDB applies an operation to initialData, instead of a snapshot, in tryCompose. I have already opened a PR with a fix.
  2. ShareDB passes a non-serialized snapshot to deserialize here.
  3. ShareDB uses createDeserialized, which is not in the spec and is not needed because the standard create already returns a non-serialized snapshot.
  4. ShareDB never calls serialize and relies on the OT types to define toJSON instead. This is not documented anywhere and violates the spec.
  5. ShareDB applies operations to serialized snapshots on the server-side because it does not deserialize the data coming from the database.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked ottypes/docs standard-properties spec, then inspect lib/client/doc.js at the cited createDeserialized, deserialize, and tryCompose paths, plus lib/ot.js and lib/submit-request.js. Compare each call with the spec and the text-tp2 examples; done means snapshots and serialized data are handled consistently across client and server, including the concerns listed in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.