Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support pre caveat in store/list and upload/list #139

Merged
merged 11 commits into from
Feb 16, 2023
Merged

Conversation

travis
Copy link
Member

@travis travis commented Feb 10, 2023

Implement support for the pre caveat introduced in storacha/w3up#423

Also introduce startCursor and endCursor with the intention to deprecate cursor. By providing cursors for the beginning and end of the range, we enable clients to page forward or backward without saving state anywhere.

Example usage:

Given uploads like:

$ w3 ls
bafybeia7tr4dgyln7zeyyyzmkppkcts6azdssykuluwzmmswysieyadcbm
bafybeibvbxjeodaa6hdqlgbwmv4qzdp3bxnwdoukay4dpl7aemkiwc2eje
bafybeid2fbwlsb7euczxw7ig3q3fyezw7tfkcikrer75w4ucfawh5vqfdm
bafybeidibxjgswcu2q4gx7j5mzq26qtcczt3nczg6k4ybqct2rm567kpoy
bafybeie7vavzb2ojufppuaxer3kfu4yxi36z7ozdz7wnhtylnd7rl5p6ji
bafybeiefiddap3p3z3p3obatviipgda2us3umt4uxeh2trrni5pt6bfc6e
bafybeifohbynkellbberk3hi447dntungwgicmsvxuwdttk5k5k535mw2a
bafybeigkeedelu7fkqgeafzh7zrtwmcn747clncxuufl2dzu46mww735qq
bafybeign7hb7ynhc6o3sevas365xuzuqzrhpfzgksi4dzpcbphl4xrerye
bafybeignyyeaqn6b2fzqswrozt2txexjbwesrt4dbxlquoac4nn7mbi2gm
bafybeigz7o2ibtv6k5pnklfza3ebsl6jeveguoyxwvrmmtvp2lkvqqjyem

You can now page forward like:

$ w3 can upload ls --size 4
bafybeia7tr4dgyln7zeyyyzmkppkcts6azdssykuluwzmmswysieyadcbm
bafybeibvbxjeodaa6hdqlgbwmv4qzdp3bxnwdoukay4dpl7aemkiwc2eje
bafybeid2fbwlsb7euczxw7ig3q3fyezw7tfkcikrer75w4ucfawh5vqfdm
bafybeidibxjgswcu2q4gx7j5mzq26qtcczt3nczg6k4ybqct2rm567kpoy
$ w3 can upload ls --size 4 --cursor bafybeidibxjgswcu2q4gx7j5mzq26qtcczt3nczg6k4ybqct2rm567kpoy
bafybeie7vavzb2ojufppuaxer3kfu4yxi36z7ozdz7wnhtylnd7rl5p6ji
bafybeiefiddap3p3z3p3obatviipgda2us3umt4uxeh2trrni5pt6bfc6e
bafybeifohbynkellbberk3hi447dntungwgicmsvxuwdttk5k5k535mw2a
bafybeigkeedelu7fkqgeafzh7zrtwmcn747clncxuufl2dzu46mww735qq
$ w3 can upload ls --size 4 --cursor bafybeigkeedelu7fkqgeafzh7zrtwmcn747clncxuufl2dzu46mww735qq
bafybeign7hb7ynhc6o3sevas365xuzuqzrhpfzgksi4dzpcbphl4xrerye
bafybeignyyeaqn6b2fzqswrozt2txexjbwesrt4dbxlquoac4nn7mbi2gm
bafybeigz7o2ibtv6k5pnklfza3ebsl6jeveguoyxwvrmmtvp2lkvqqjyem

and page backward like:

$ w3 can upload ls --size 4 --cursor bafybeign7hb7ynhc6o3sevas365xuzuqzrhpfzgksi4dzpcbphl4xrerye --pre
bafybeigkeedelu7fkqgeafzh7zrtwmcn747clncxuufl2dzu46mww735qq
bafybeifohbynkellbberk3hi447dntungwgicmsvxuwdttk5k5k535mw2a
bafybeiefiddap3p3z3p3obatviipgda2us3umt4uxeh2trrni5pt6bfc6e
bafybeie7vavzb2ojufppuaxer3kfu4yxi36z7ozdz7wnhtylnd7rl5p6ji
$ w3 can upload ls --size 4 --cursor bafybeie7vavzb2ojufppuaxer3kfu4yxi36z7ozdz7wnhtylnd7rl5p6ji --pre
bafybeidibxjgswcu2q4gx7j5mzq26qtcczt3nczg6k4ybqct2rm567kpoy
bafybeid2fbwlsb7euczxw7ig3q3fyezw7tfkcikrer75w4ucfawh5vqfdm
bafybeibvbxjeodaa6hdqlgbwmv4qzdp3bxnwdoukay4dpl7aemkiwc2eje
bafybeia7tr4dgyln7zeyyyzmkppkcts6azdssykuluwzmmswysieyadcbm

Note that the cursor values here happen to match the CID strings - this is an implementation detail and should not be relied upon. Instead, cursor values should be taken from startCursor and endCursor in the list response:

$ w3 can upload ls --size 4 --cursor bafybeidibxjgswcu2q4gx7j5mzq26qtcczt3nczg6k4ybqct2rm567kpoy --raw
{"size":4,"cursor":"bafybeigkeedelu7fkqgeafzh7zrtwmcn747clncxuufl2dzu46mww735qq","results":[{"root":{"/":"bafybeie7vavzb2ojufppuaxer3kfu4yxi36z7ozdz7wnhtylnd7rl5p6ji"},"shards":[{"/":"bagbaieracmkgwrw6rowsk5jse5eihyhszyrq5w23aqosajyckn2tfbotdcqq"}],"updatedAt":"2023-02-13T16:30:04.172Z","insertedAt":"2023-02-13T16:30:04.172Z"},{"root":{"/":"bafybeiefiddap3p3z3p3obatviipgda2us3umt4uxeh2trrni5pt6bfc6e"},"shards":[{"/":"bagbaieraz3iyicghnyzpjld7yxf7rmntf5cdbewo4pmuck6kkkc6f7z3sznq"}],"updatedAt":"2023-02-13T16:29:51.864Z","insertedAt":"2023-02-13T10:57:39.017Z"},{"root":{"/":"bafybeifohbynkellbberk3hi447dntungwgicmsvxuwdttk5k5k535mw2a"},"shards":[{"/":"bagbaierasu5cufqagk34dkmhszbwuhiydjjjp3pl4bacyvskljqtkcxhgbta"}],"updatedAt":"2023-02-13T16:30:11.648Z","insertedAt":"2023-02-13T10:57:16.264Z"},{"root":{"/":"bafybeigkeedelu7fkqgeafzh7zrtwmcn747clncxuufl2dzu46mww735qq"},"shards":[{"/":"bagbaieralqhbrq2mqupqijkoylagbams263jwq6helsl6kbdpivupjm7egxq"}],"updatedAt":"2023-02-13T16:30:18.403Z","insertedAt":"2023-02-13T10:57:49.695Z"}],
 "endCursor":"bafybeigkeedelu7fkqgeafzh7zrtwmcn747clncxuufl2dzu46mww735qq","startCursor":"bafybeie7vavzb2ojufppuaxer3kfu4yxi36z7ozdz7wnhtylnd7rl5p6ji"}

nb that these w3 commands require the changes I implemented in storacha/w3cli#45

this implements support for the `prev` caveat proposed in storacha/w3up#423

I'm not sure the semantics are right yet, deploying to get a test env to play with
and use it to implement support for the `pre` caveat in `store/list` and `upload/list`
@seed-deploy seed-deploy bot temporarily deployed to pr139 February 10, 2023 06:55 Inactive
@seed-deploy
Copy link

seed-deploy bot commented Feb 10, 2023

View stack outputs
  • pr139-w3infra-CarparkStack

    Name Value
    BucketName carpark-pr139-0
    Region us-east-2
  • pr139-w3infra-SatnavStack

    Name Value
    BucketName satnav-pr139-0
    Region us-east-2
  • pr139-w3infra-UploadApiStack

    Name Value
    ApiEndpoint https://0xt3x88ch9.execute-api.us-east-2.amazonaws.com
    CustomDomain https://pr139.up.web3.storage
  • pr139-w3infra-BusStack

  • pr139-w3infra-ReplicatorStack

  • pr139-w3infra-UcanInvocationStack

  • pr139-w3infra-UploadDbStack

@seed-deploy seed-deploy bot temporarily deployed to pr139 February 10, 2023 19:12 Inactive
@seed-deploy seed-deploy bot temporarily deployed to pr139 February 10, 2023 19:51 Inactive
@seed-deploy seed-deploy bot temporarily deployed to pr139 February 10, 2023 20:36 Inactive
after working with dynamo a bit, I realized that adding
startCursor and endCursor to the response, combined with the new `pre`
caveat gives us fully stateless bi-directional paging!

I'd like to propose we deprecate `cursor` in favor of `startCursor` and
`endCursor`. even if we end up moving
to an implementation that doesn't support `startCursor`, `endCursor`
feels a bit clearer, and we don't have as tight space constraints in these
responses as we do in caveats that get included in UCANs
@seed-deploy seed-deploy bot temporarily deployed to pr139 February 13, 2023 16:17 Inactive
Copy link
Contributor

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look good! Thanks @travis
Can we please add some tests for this under upload-api/test/service/{store, upload}.test.js?

@vasco-santos
Copy link
Contributor

vasco-santos commented Feb 14, 2023

Also @travis @gobengo thanks for dealing with all this deps upgrades in the PR ❤️

travis added a commit to storacha/w3up that referenced this pull request Feb 14, 2023
per the change in storacha/w3infra#139, add startCursor and endCursor and deprecate cursor
travis added a commit to storacha/w3ui that referenced this pull request Feb 14, 2023
Use the new `pre` caveat and `startCursor` and `endCursor` from storacha/w3infra#139 to implement reverse paging.

One unsatisfying issue with this is that paging backwards reverses the
order of items in the uploads list, and that edge conditions
behave fairly confusingly.

Not entirely sure what to do about this yet, so pushing up for some feedback.

This currently only works with a bunch of custom service config and `file:/`
dependencies that I am not pushing up for now.
1) cleaner endCursor handling
2) add deprecation comments
@seed-deploy seed-deploy bot temporarily deployed to pr139 February 14, 2023 10:27 Inactive
@travis
Copy link
Member Author

travis commented Feb 14, 2023

Can we please add some tests for this under upload-api/test/service/{store, upload}.test.js?

Ah yes - will jump on this tomorrow most likely!

@seed-deploy seed-deploy bot temporarily deployed to pr139 February 15, 2023 04:43 Inactive
@seed-deploy seed-deploy bot temporarily deployed to pr139 February 15, 2023 05:06 Inactive
@seed-deploy seed-deploy bot temporarily deployed to pr139 February 15, 2023 05:21 Inactive
@seed-deploy seed-deploy bot temporarily deployed to pr139 February 15, 2023 05:29 Inactive
@travis
Copy link
Member Author

travis commented Feb 15, 2023

ok @vasco-santos got some tests in, please take a look!

two questions came out of this:
a) is it worth trying to get the tests running on my local or will that require extensive AWS config that's more trouble than it's worth?
b) these tests reuse a ton of boilerplate - I see some opportunities to DRY things up quite a bit, but notice you haven't done much of that up until now - are you intentionally avoiding getting rid of some of the boilerplate? if not, any objection to me spending a little time making things a little tighter? I'm thinking that wrapping all of the capability creation in a more readable test-specific API would be pretty straightforward and clean a bunch of these tests up...

@travis travis requested a review from vasco-santos February 15, 2023 05:57
Copy link
Contributor

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@vasco-santos
Copy link
Contributor

We synced offline in a, should be good to go with Docker installed locally. But maybe there is a requirement so have some environment variables AWS specific setup (per CI file).

b) we can do in follow up per discussion in sync later

@travis travis merged commit 7ae751d into main Feb 16, 2023
@travis travis deleted the feat/paging-prev branch February 16, 2023 05:27
travis added a commit to storacha/w3up that referenced this pull request Feb 16, 2023
per the change in storacha/w3infra#139, add
startCursor and endCursor and deprecate cursor
travis added a commit to storacha/w3ui that referenced this pull request Feb 23, 2023
Use the new `pre` caveat and `before` and `after` cursors from
storacha/w3infra#139 to implement reverse
paging in the uploads list headless components and w3console


https://user-images.githubusercontent.com/1113/218706799-a0cac0cd-7da2-47d5-b19e-a2bc41ceda2f.mov
gobengo pushed a commit to storacha/w3up that referenced this pull request Apr 11, 2023
per the change in storacha/w3infra#139, add
startCursor and endCursor and deprecate cursor
Peeja pushed a commit to storacha/upload-service that referenced this pull request Jan 29, 2025
Use the new `pre` caveat and `before` and `after` cursors from
storacha/w3infra#139 to implement reverse
paging in the uploads list headless components and w3console


https://user-images.githubusercontent.com/1113/218706799-a0cac0cd-7da2-47d5-b19e-a2bc41ceda2f.mov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants