Description
These are some of my thoughts around enabling more extensibility of ShareDB and more rapid development of new ideas. I'm hoping to find some time in the next month or two to write a more fleshed out spec, but in the meantime, comments and more ideas are welcome!
ShareDB message protocol plugins
Over the past couple years, there have been new features that require extending the ShareDB message protocol with different request.a
"actions":
fetchSnapshotByTimestamp
- Presence, still in progress
These are handled in large switch statements:
- On the server in Agent: https://github.com/share/sharedb/blob/v1.1.0/lib/agent.js#L334
- On the client in Connection: https://github.com/share/sharedb/blob/v1.1.0/lib/client/connection.js#L183
I've been thinking it would be good to implement a framework for message protocol plugins, and refactor more optional features like queries, fetchSnapshotByTimestamp
, and presence into plugins. This has some nice advantages:
- ShareDB users could choose exactly what features they want, keeping code and bundle sizes smaller.
- We can develop new protocol-level features more rapidly as independent plugins, compared to developing them in ShareDB core. They can also be independently semver'd.
- ShareDB users could author their own protocol plugins without needing to touch ShareDB core.
One of the requirements to accomplishing this is that clients and servers need to be able to do some sort of capability handshake, so they can agree on what protocol plugins to use for the session and at what versions.
Client/server capability handshake
I haven't put much thought into this yet. It could work like a simpler version of a TLS handshake. It would need to include at least:
- Capability names
- Capability versions
Potential use cases for a capability handshake:
- ShareDB message protocol plugins
- Making it easier to do major semver updates to ShareDB core
- Negotiating a default OT type or supported OT types in general: A specific version of ot-json0 is hardcoded as the basic type #284
- Custom application-specific capabilities defined by ShareDB users