Skip to content

Commit

Permalink
feat: implement getCID methods on store and upload tables
Browse files Browse the repository at this point in the history
this enables the new capability invocation handlers in storacha/w3up#918
  • Loading branch information
travis committed Sep 13, 2023
1 parent ff92360 commit b81c071
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 58 deletions.
80 changes: 24 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions upload-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"@ucanto/validator": "^8.0.0",
"@web-std/fetch": "^4.1.0",
"@web3-storage/access": "^14.0.0",
"@web3-storage/capabilities": "^9.0.0",
"@web3-storage/upload-api": "^5.3.0",
"@web3-storage/capabilities": "^9.3.0",
"@web3-storage/upload-api": "^5.4.0",
"@web3-storage/w3infra-ucan-invocation": "*",
"multiformats": "^11.0.1",
"nanoid": "^4.0.2",
Expand Down
27 changes: 27 additions & 0 deletions upload-api/tables/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,33 @@ export function useStoreTable(dynamoDb, tableName) {
}
}
},

/**
* Get information about a CID.
*
* @param {import('@web3-storage/upload-api').UnknownLink} link
*/
async getCID (link) {
const response = await dynamoDb.send(new QueryCommand({
TableName: tableName,
IndexName: 'cid',
KeyConditionExpression: "link = :link",
ExpressionAttributeValues: {
':link': { S: link.toString() }
}
}))
return {
spaces: response.Items ? response.Items.map(
i => {
const item = unmarshall(i)
return ({
did: item.space,
insertedAt: item.insertedAt
})
}
) : []
}
}
}
}

Expand Down
27 changes: 27 additions & 0 deletions upload-api/tables/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,33 @@ export function useUploadTable(dynamoDb, tableName) {
results: options.pre ? results.reverse() : results,
}
},

/**
* Get information about a CID.
*
* @param {import('@web3-storage/upload-api').UnknownLink} link
*/
async getCID (link) {
const response = await dynamoDb.send(new QueryCommand({
TableName: tableName,
IndexName: 'cid',
KeyConditionExpression: "root = :root",
ExpressionAttributeValues: {
':root': { S: link.toString() }
}
}))
return {
spaces: response.Items ? response.Items.map(
i => {
const item = unmarshall(i)
return ({
did: item.space,
insertedAt: item.insertedAt
})
}
) : []
}
}
}
}

Expand Down

0 comments on commit b81c071

Please sign in to comment.