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: add support for list pagination in list capability invocations #184

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/access-client/src/capabilities/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ export const list = base.derive({
* be stored.
*/
with: URI.match({ protocol: 'did:' }),
nb: {
/**
* A pointer that can be moved back and forth on the list.
* It can be used to paginate a list for instance.
*/
cursor: Schema.string().optional(),
/**
* Maximum number of items per page.
*/
size: Schema.integer().optional(),
},
derives: (claimed, delegated) => {
if (claimed.with !== delegated.with) {
return new Failure(
Expand Down
15 changes: 13 additions & 2 deletions packages/access-client/src/capabilities/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @module
*/
import { capability, Link, URI } from '@ucanto/validator'
import { capability, Link, URI, Schema } from '@ucanto/validator'
import { codec as CAR } from '@ucanto/transport/car'
import { equalWith, fail, equal } from './utils.js'
import { top } from './top.js'
Expand Down Expand Up @@ -140,6 +140,17 @@ export const list = base.derive({
to: capability({
can: 'upload/list',
with: URI.match({ protocol: 'did:' }),
nb: {
/**
* A pointer that can be moved back and forth on the list.
* It can be used to paginate a list for instance.
*/
cursor: Schema.string().optional(),
/**
* Maximum number of items per page.
*/
size: Schema.integer().optional(),
},
}),
/**
* `upload/list` can be derived from the `upload/*` & `*` capability
Expand All @@ -150,4 +161,4 @@ export const list = base.derive({

// ⚠️ We export imports here so they are not omited in generated typedefs
// @see https://github.com/microsoft/TypeScript/issues/51548
export { Link }
export { Link, Schema }
4 changes: 4 additions & 0 deletions packages/access-client/test/capabilities/upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ describe('upload capabilities', function () {
audience: w3,
with: account.did(),
proofs: [await any],
nb: {},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Types require empty object when all nb properties are optional. need to look

Copy link
Contributor

Choose a reason for hiding this comment

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

this should not happen theres a lot of infer types in ucanto to mitigate this. Did you open an issue in ucanto ?

})

const result = await access(await list.delegate(), {
Expand Down Expand Up @@ -357,6 +358,7 @@ describe('upload capabilities', function () {
issuer: bob,
with: account.did(),
proofs: [await upload.delegate()],
nb: {},
})

const result = await access(await list.delegate(), {
Expand All @@ -379,13 +381,15 @@ describe('upload capabilities', function () {
audience: bob,
with: account.did(),
proofs: [await any],
nb: {},
})

const list = Upload.list.invoke({
audience: w3,
issuer: bob,
with: account.did(),
proofs: [await delegation.delegate()],
nb: {},
})

const result = await access(await list.delegate(), {
Expand Down