Skip to content
This repository was archived by the owner on Sep 9, 2021. It is now read-only.
This repository was archived by the owner on Sep 9, 2021. It is now read-only.

disinguish between key and value queries #38

@Gozala

Description

@Gozala

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:

  1. If you do not pass {keysOnly:true} it returns AsyncIterable<{key:Key, value:Buffer}>, meaning all of the documentation is wrong.
  2. If you do pass {keysOnly:true} it returns AsyncIterable<{key:Key}> that non of the documentation seems to cover.

I would like to propose:

  1. Make a DataStore interface generic as in DataStore<Key, Value, Entry> this would make
    • Raw data store DataStore<Key, Buffer, [Key, Buffer]> (entry follows Object.entries() idiom of representing key values as tuples)
  • Block data store DataStore<CID, Block, Block> as blocks represent both values and entries.
  1. 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>
  2. 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 JS for await ([key] of store.query({...}) {...}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    need/triageNeeds initial labeling and prioritization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions