Add support for the direction option in getAll and getAllKeys#350
Open
ghazi-git wants to merge 1 commit intojakearchibald:mainfrom
Open
Add support for the direction option in getAll and getAllKeys#350ghazi-git wants to merge 1 commit intojakearchibald:mainfrom
ghazi-git wants to merge 1 commit intojakearchibald:mainfrom
Conversation
add overloads of getAll and getAllKeys to enable calling the methods by passing an options object containing query, count and (the new) direction. Also, update the tests to include an example of calling the methods by passing an options object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The indexedDB spec added support for calling the
getAllandgetAllKeysmethods using an options objects containing query, count and (the new) direction. Here are the links to the updated spec forstore.getAllandstore.getAllKeysand the updated spec forindex.getAllandindex.getAllKeys. Notice how direction's type isnext|prevfor the store methods, while it isnext|prev|nextunique|prevuniquefor the index methods.For this PR, I chose to add new overloads to make it clear that the separate count argument is ignored when passing an options object. I also added usage examples in the tests, mostly to make sure the new options object works as expected (tested the functionality with chrome 141 beta). In tests, feature detection using
if ('getAllRecords' in store)is based on the recommendation in the original proposal.Now the problem: I expected type assertions (like the one below) for the first argument of the
getAllandgetAllKeysto fail, but that didn't happen.idb/test/main.ts
Lines 1200 to 1205 in 77dd8be
Specifically, I expected that I need to append
| { query?: string | IDBKeyRange | null; count?: number; direction?: 'next' | 'prev'}since the first argument can be an options object. However, it turns out typescript keeps inferring the type as before since the new overload is added first in the interface.So, @jakearchibald what do you think we should do? one option is to leave things as they are now, especially that the new overloads avoid library users specifying the separate count argument by mistake. The other option is to extend the union type of query (and maybe rename query to
queryOrOptionslike in the spec) instead of using function overloads. This should lead to updating the type assertions in tests, but does not prevent users from passing count by mistake. Or maybe there is another option.