Repository navigation
feat!: the empty cursor is the empty page token, both ways - #9
Merged
Merged
Conversation
A first page had no cursor and a last page returned `None`, so every caller special-cased the empty `page_token` on the way in and mapped `None` to it on the way out -- the same branch the blank filter needed before #8. AIP-158 reads the empty token as the first page in a request and as "no more pages" in a response. `Cursor` gains a default, the empty cursor -- no keys, no position -- and `is_empty()`. `Cursor::parse("")` returns it and `encode()` of it returns "", so a token and a cursor are each other's image, empty one included. `with_cursor` takes the empty cursor as no cursor, which also keeps it clear of the order_by mismatch check a first page would otherwise fail. `Page::cursor` is a plain `Cursor`, empty on the last page. BREAKING CHANGE: `Page::cursor` is `Cursor`, not `Option<Cursor>`: test `is_empty()` for the last page. `Cursor::parse("")` returns `Ok` with the empty cursor rather than a token error.
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.
A first page had no cursor, and a last page returned
None. So every caller special-cased the emptypage_tokenon the way in and turnedNoneback into it on the way out. It's the same branch the blank filter needed before #8. AIP-158 reads the empty token as the first page in a request, and as "no more pages" in a response.Cursorgains a default, the empty cursor (no keys, no position), andis_empty().Cursor::parse("")(or whitespace) returns it, andencode()of it returns"".with_cursor(empty)is no cursor: nothing is AND-ed in. There's also no cursor ordering to compare an explicitorder_byagainst, so a first page can't tripCursorMismatch. A later empty cursor clears an earlier one, just as a secondwith_cursorreplaces the first.Page::cursoris a plainCursor, empty on the last page.Pagerdocs note that over an empty ordering every page is the last, since there's nothing to position by.Breaking:
Page::cursorisCursor, notOption<Cursor>; checkis_empty()for the last page.Cursor::parse("")now returnsOkwith the empty cursor instead of a token error.Tests:
order_by;The README's keyset section is updated.