Skip to content

Commit

Permalink
feat: support prev caveat in store/list and upload/list
Browse files Browse the repository at this point in the history
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
  • Loading branch information
travis committed Feb 6, 2023
1 parent 46ae012 commit a5a3ffd
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions upload-api/service/store/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ export function storeListProvider(context) {
return Server.provide(
Store.list,
async ({ capability }) => {
const { cursor, size } = capability.nb
const { cursor, size, prev } = capability.nb
const space = Server.DID.parse(capability.with).did()

return await context.storeTable.list(space, {
size,
cursor
cursor,
prev
})
}
)
Expand Down
3 changes: 2 additions & 1 deletion upload-api/service/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export interface UploadListItem extends UploadAddResult {

export interface ListOptions {
size?: number,
cursor?: string
cursor?: string,
prev?: boolean
}

export interface ListResponse<R> {
Expand Down
5 changes: 3 additions & 2 deletions upload-api/service/upload/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ export function uploadListProvider(context) {
return Server.provide(
Upload.list,
async ({ capability }) => {
const { cursor, size } = capability.nb
const { cursor, size, prev } = capability.nb
const space = Server.DID.parse(capability.with).did()

return await context.uploadTable.list(space, {
size,
cursor
cursor,
prev
})
})
}
1 change: 1 addition & 0 deletions upload-api/tables/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export function createStoreTable (region, tableName, options = {}) {
AttributeValueList: [{ S: space }],
},
},
ScanIndexForward: options.prev ? false : true,
ExclusiveStartKey: exclusiveStartKey,
AttributesToGet: ['link', 'size', 'origin', 'insertedAt'],
})
Expand Down
1 change: 1 addition & 0 deletions upload-api/tables/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export function createUploadTable (region, tableName, options = {}) {
AttributeValueList: [{ S: space }],
},
},
ScanIndexForward: options.prev ? false : true,
ExclusiveStartKey: exclusiveStartKey,
AttributesToGet: ['space', 'root', 'shards', 'insertedAt', 'updatedAt'],
})
Expand Down

0 comments on commit a5a3ffd

Please sign in to comment.