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: implement getCID methods on store and upload tables #225

Merged
merged 4 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
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.1",
"@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