Skip to content

Commit

Permalink
feat: add pre caveat to store/list and upload/list (#423)
Browse files Browse the repository at this point in the history
Per storacha/w3ui#143 we'd like to give
clients a way to get the previous page of results rather than the next
page.

This change introduces a `pre` caveat which, when set to true, will
return the page of results preceding `cursor`.

I considered calling this `reverse` or `rev` but I think that implies
that results will be returned sorted in reverse, which is not the
intent.

---------

Co-authored-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
travis and Alan Shaw authored Feb 10, 2023
1 parent e0f67e8 commit 9cce414
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/capabilities/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ export const list = base.derive({
* Maximum number of items per page.
*/
size: Schema.integer().optional(),
/**
* If true, return page of results preceding cursor. Defaults to false.
*/
pre: Schema.boolean().optional(),
},
derives: (claimed, delegated) => {
if (claimed.with !== delegated.with) {
Expand Down
4 changes: 4 additions & 0 deletions packages/capabilities/src/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ export const list = base.derive({
* Maximum number of items per page.
*/
size: Schema.integer().optional(),
/**
* If true, return page of results preceding cursor. Defaults to false.
*/
pre: Schema.boolean().optional(),
},
}),
/**
Expand Down
1 change: 1 addition & 0 deletions packages/upload-client/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export async function list(
nb: {
cursor: options.cursor,
size: options.size,
pre: options.pre,
},
})
.execute(conn)
Expand Down
4 changes: 4 additions & 0 deletions packages/upload-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ export interface Pageable {
* Maximum number of items to return.
*/
size?: number
/**
* If true, return page of results preceding cursor. Defaults to false.
*/
pre?: boolean
}

export interface RequestOptions extends Retryable, Abortable, Connectable {}
Expand Down
1 change: 1 addition & 0 deletions packages/upload-client/src/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export async function list(
nb: {
cursor: options.cursor,
size: options.size,
pre: options.pre,
},
})
.execute(conn)
Expand Down
8 changes: 8 additions & 0 deletions spec/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,13 @@ The `with` field of the invocation must be set to the DID of the memory space to

`cursor` can be set to start listing from an item in the middle of the list. Its value should be a `cursor` returned by a previous invocation of `store/list`
`size` can be set to change the number of items returned by an `store/list` invocation
`pre` can be set to `true` to return the page of results preceding `cursor` rather than the results after `cursor`. Defaults to `false`.

| field | value | required? | context |
| ----------- | ------------------------ | --------- | --------------------------------------------------------------- |
| `nb.cursor` | string || A cursor returned by a previous invocation |
| `nb.size` | integer || The maximum number of results to return |
| `nb.pre` | boolean || If true, return the page of results preceeding the cursor |

## `upload/` namespace

Expand Down Expand Up @@ -286,12 +288,18 @@ The `with` field of the invocation must be set to the DID of the memory space to

`cursor` can be set to start listing from an item in the middle of the list. Its value should be a `cursor` returned by a previous invocation of `upload/list`
`size` can be set to change the number of items returned by an `upload/list` invocation
`pre` can be set to `true` to return the page of results preceding `cursor` rather than the results after `cursor`. Defaults to `false`.

| field | value | required? | context |
| ----------- | ------------------------ | --------- | --------------------------------------------------------------- |
| `nb.cursor` | string || A cursor returned by a previous invocation |
| `nb.size` | integer || The maximum number of results to return |

| field | value | required? | context |
| ----------- | ------------------------ | --------- | --------------------------------------------------------------- |
| `nb.cursor` | string || A cursor returned by a previous invocation |
| `nb.size` | integer || The maximum number of results to return |
| `nb.pre` | boolean || If true, return the page of results preceeding the cursor |
## `voucher/` namespace

TODO: more voucher docs when implementation details settle down a bit.
Expand Down

0 comments on commit 9cce414

Please sign in to comment.