abstract-dat
A common interface for hypercore based data-structures
There's a lot of hypercores based data structures. When working on higher-level tools, oftenly it does not really matter whether you're dealing with a hyperdrive, a hypercore, a hypertrie, a hyperdb, a multifeed instance or even a kappa-core or a cabal.
Most of these need, in their constructor:
- A
random-access-storage instance
- A key, or a key pair, when wanting to sync an existing archive
- An
opts object
They also all have a sufficiently similar public API that ususally, apart from the structure-specific methods, include:
key: The public key (Buffer)
discoveryKey: The discovery key (Buffer)
ready (cb): Async constructor
replicate (opts): Create a hypercore-protocol stream for replication (or use one passed as opts.stream)
Structures that are composed of more than one hypercore oftenly also expose a feeds(cb) method that invokes cb with a list of hypercores. There should maybe be a second argument to the callback function that contains type-sepcific metadata for the feeds (e.g. content vs metadata feeds in hypercore).
Some of the more recent data structures can accept a hypercore factory/constructor, either as argument or option. If that is passed, a storage instance is not needed anymore.
There's also a lot of common options, mostly derived from hypercore: sparse, live, valueEncoding
If we turn this abstract-dat interface into a standard (maybe like in the random-access-storage ecosytem), higher level tools can easily work with different data structures. Examples for higher level tools are libraries/managers of multiple dats, debug tools like dat-doctor, and hopefully soon something like a dat-sdk.
Additionally, higher-level tools like cabal could easily also adhere to such an interface, and thus be managed with the same tools as hyperdrives etc.
It's very little that's not already common. One thing is the question of hypercore factory vs. storage instance for structures composed out of hypercores. I'd propose to stay with the storage instance as default, but always also support a hypercore opt that has a hypercore factory (but then the storage arg would be null?). This is pretty much the only difference in signature that I could find (multifeed has a hypercore constructor as first arg, while all others have a storage instance (or path).
I'm not completely sure what the best process for such a standardization is, it would likely involve two parts:
- settle on a common interface: Would need maybe a little more research, and then a DEP with the documentation, I guess.
- settle on naming: I quite like
abstract-dat as a label for hypercore based data structure but please give other suggestions if you have some
- adopt it across the ecosystem: Might need new major versions for some tools
Anyway, I'm creating this issue first to gather some feedback before writing up a DEP :-)
abstract-dat
A common interface for hypercore based data-structures
There's a lot of hypercores based data structures. When working on higher-level tools, oftenly it does not really matter whether you're dealing with a hyperdrive, a hypercore, a hypertrie, a hyperdb, a multifeed instance or even a kappa-core or a cabal.
Most of these need, in their constructor:
random-access-storageinstanceoptsobjectThey also all have a sufficiently similar public API that ususally, apart from the structure-specific methods, include:
key: The public key (Buffer)discoveryKey: The discovery key (Buffer)ready (cb): Async constructorreplicate (opts): Create a hypercore-protocol stream for replication (or use one passed as opts.stream)Structures that are composed of more than one hypercore oftenly also expose a
feeds(cb)method that invokescbwith a list of hypercores. There should maybe be a second argument to the callback function that contains type-sepcific metadata for the feeds (e.g. content vs metadata feeds in hypercore).Some of the more recent data structures can accept a
hypercorefactory/constructor, either as argument or option. If that is passed, astorageinstance is not needed anymore.There's also a lot of common options, mostly derived from hypercore:
sparse,live,valueEncodingIf we turn this
abstract-datinterface into a standard (maybe like in therandom-access-storageecosytem), higher level tools can easily work with different data structures. Examples for higher level tools are libraries/managers of multiple dats, debug tools like dat-doctor, and hopefully soon something like adat-sdk.Additionally, higher-level tools like
cabalcould easily also adhere to such an interface, and thus be managed with the same tools as hyperdrives etc.It's very little that's not already common. One thing is the question of hypercore factory vs. storage instance for structures composed out of hypercores. I'd propose to stay with the storage instance as default, but always also support a
hypercoreopt that has a hypercore factory (but then the storage arg would be null?). This is pretty much the only difference in signature that I could find (multifeed has a hypercore constructor as first arg, while all others have a storage instance (or path).I'm not completely sure what the best process for such a standardization is, it would likely involve two parts:
abstract-datas a label for hypercore based data structure but please give other suggestions if you have someAnyway, I'm creating this issue first to gather some feedback before writing up a DEP :-)