This repository was archived by the owner on Sep 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
This repository was archived by the owner on Sep 9, 2021. It is now read-only.
disinguish between key and value queries #38
Copy link
Copy link
Open
Labels
need/triageNeeds initial labeling and prioritizationNeeds initial labeling and prioritization
Description
In the process of adding some types into js-ipfs (ipfs/js-ipfs#2945) I have discovered what appeared to be an error either in declared interface (in readme here or more specifically https://github.com/ipfs/js-ipfs-repo/blob/77a0cdc944ce7fc47f520ab38705259a28cea1dc/src/blockstore.js#L25-L34)
Docs say query returns docs say query returns AsyncIterator<Block>
while in practice it appeared to return AsyncIterator<{key:Key, ...?}>
As that is how code in js-ipfs used it:
https://github.com/ipfs/js-ipfs/blob/80c6fdf1c3ad6aaae14eb4297b7b183fd4fa1311/packages/ipfs/src/core/components/refs/local.js#L9
After digging around this repo it appears that:
- If you do not pass
{keysOnly:true}
it returnsAsyncIterable<{key:Key, value:Buffer}>
, meaning all of the documentation is wrong. - If you do pass
{keysOnly:true}
it returnsAsyncIterable<{key:Key}>
that non of the documentation seems to cover.
I would like to propose:
- Make a
DataStore
interface generic as inDataStore<Key, Value, Entry>
this would make- Raw data store
DataStore<Key, Buffer, [Key, Buffer]>
(entry followsObject.entries()
idiom of representing key values as tuples)
- Raw data store
- Block data store
DataStore<CID, Block, Block>
as blocks represent both values and entries.
- Update documentation so that query reutrns
AsyncIterable<Entry>
instead.- In raw data store that is
AsyncIterable<[Key, Buffer]>
- In block data store that is
AsyncIterable<Block>
- In raw data store that is
- Consider alternative to
keysOnly
options. Because not only it complicates API and makes it hard to document but it's also easy to miss if query options are passed into making it unclear what result would be.- Option 1: Just create another
queryKeys(...):AsyncIterable<Key>
method. This is my preference because in some cases it can be better optimized (e.g. when queries occur across process or thread boundaries). - Option 2: If adding a method seems like no-go, how about just remove
keysOnly
in favor of destructuring in JSfor await ([key] of store.query({...}) {...}
.
- Option 1: Just create another
Metadata
Metadata
Assignees
Labels
need/triageNeeds initial labeling and prioritizationNeeds initial labeling and prioritization