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:
- ShareDB applies an operation to
initialData, instead of a snapshot, in tryCompose. I have already opened a PR with a fix.
- ShareDB passes a non-serialized snapshot to
deserialize here.
- ShareDB uses createDeserialized, which is not in the spec and is not needed because the standard
create already returns a non-serialized snapshot.
- ShareDB never calls
serialize and relies on the OT types to define toJSON instead. This is not documented anywhere and violates the spec.
- ShareDB applies operations to serialized snapshots on the server-side because it does not deserialize the data coming from the database.
Spec: https://github.com/ottypes/docs#standard-properties
First of all, according to the spec,
initialData,snapshotanddatamay all be completely different data types in the following function specscreate([initialData]) -> snapshot,serialize(snapshot) -> data,deserialize(data) -> snapshot. text-tp2 is an example of such a type. Please note also thatcreate([initialData]) -> snapshotreturns 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:
initialData, instead of asnapshot, in tryCompose. I have already opened a PR with a fix.deserializehere.createalready returns a non-serialized snapshot.serializeand relies on the OT types to definetoJSONinstead. This is not documented anywhere and violates the spec.