dagdb
dagdb copied to clipboard
feat: return async iterable from resolver functions
Resolvers are custom functions that can resolve conflicts on pulls and pushes between stores. Currently, they are limited in scope, and look like this:
type Resolver = (locals: Block[], remotes: Block[], get: (cid: CID) => Promise<Block>) => Promise<Block[]>
Where the response in an array of Blocks, the last of which is an Operation (set
or get
). Downstream callers make some strong assumptions about the structure of that response. This makes it slightly harder to consume later, and the API does not match other user-land APIs, such as the custom types API which expects an AsyncIterable of Blocks.
It would be useful, therefore, to have custom Resolvers return an AsyncIterable of Blocks, the last of which, is always the Operation. This makes it easy to create new Blocks as part of the resolution strategy, and pass those along to any downstream consumers.
In practice, this is a reply minimal change, but will make the API cleaner. For tests, it would then be useful to have an additional test that checks and handles the creation of new Blocks as part of the resolution outcome.