earthstar-project / earthstar

Storage for private, distributed, offline-first applications.
https://earthstar-project.org
GNU Lesser General Public License v3.0
637 stars 20 forks source link

Server APIs + new Path class #333

Closed sgwilym closed 4 months ago

sgwilym commented 4 months ago

This PR ports the existing Server API and some of its extensions, as well as adding a new Path class.

Server

The server API has been ported with one major change: a Peer is now provided alongside the extensions during instantiation. This allows us to get rid of a few extensions like ExtensionKnownShares, the only purpose of which was to configure the Peer. This can now be done prior to the instantiation of the server and in any manner the user wishes.

Server extensions

Path

Willow defines paths as a sequence of bytestrings, in contrast with Earthstar's paths which were made up of strings with a restricted character set. But if Earthstar is to support features such as encryption, it cannot further restrict Willow's definition of a Path. However, we do not want to lose the accessibility which string-based paths brought to creating and undestanding paths.

The new Path class wraps an underlying Path as defined by Willow: a sequence of bytestrings. However, the Path class offers many methods which allow simpler path creation and viewing than you'd get by interacting with Uint8Array, for example:

And there are many utility methods such as isPrefixOf, withSuffix etc. Please see the diff for the full range of (documented) methods.