-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add blob protocol to infra (#353)
This PR creates stores and wires up new `upload-api` running `blob/add`, `web3.storage/blob/allocate`, `web3.storage/blob/accept` and `ucan/conclude` capabilities. Tests are also imported from `upload-api` implementation and run here. As agreed on storacha/w3up#1343 , there won't be any deduping between old world and new world. Therefore, we have new `allocations` table, and use different key schema in `carpark`. We are writing blobs keyed as `base58btc` as previously discussed as `${base58btcEncodedMultihash}/${base58btcEncodedMultihash}.blob`. I added `.blob` suffix but I am happy to other suggestions. Depending on how we progress with the reads side, we can consider creating a new bucket to fully isolate new content? The `receipts` and `tasks` storage end up being more complicated as they need to follow https://github.com/web3-storage/w3infra/blob/main/docs/ucan-invocation-stream.md#buckets, and is essentially the same as what happens on https://github.com/web3-storage/w3infra/blob/main/upload-api/ucan-invocation.js#L66 but at a different level as this is a proactive write of tasks and receipts.
- Loading branch information
1 parent
50b266f
commit 13566fe
Showing
22 changed files
with
1,415 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @typedef {import('@web3-storage/upload-api/types').TasksScheduler} TasksSchedulerInterface | ||
* @typedef {import('@web3-storage/upload-api/types').Service} Service | ||
* @typedef {import('@ucanto/interface').ConnectionView<Service>} Connection | ||
* @typedef {import('@ucanto/interface').ServiceInvocation} ServiceInvocation | ||
* @typedef {import('@ucanto/interface').Failure} Failure | ||
* @typedef {import('@ucanto/interface').Unit} Unit | ||
* @typedef {import('@ucanto/interface').Result<Unit, Failure>} Result | ||
*/ | ||
|
||
/** | ||
* @param {() => Connection} getServiceConnection | ||
*/ | ||
export const createTasksScheduler = (getServiceConnection) => new TasksScheduler(getServiceConnection) | ||
|
||
/** | ||
* @implements {TasksSchedulerInterface} | ||
*/ | ||
export class TasksScheduler { | ||
/** | ||
* | ||
* @param {() => Connection} getServiceConnection | ||
*/ | ||
constructor (getServiceConnection) { | ||
this.getServiceConnection = getServiceConnection | ||
} | ||
|
||
/** | ||
* @param {ServiceInvocation} invocation | ||
* @returns {Promise<Result>} | ||
*/ | ||
async schedule(invocation) { | ||
const connection = this.getServiceConnection() | ||
// This performs a HTTP Request to the Service URL. | ||
// upload-api service URL stores received invocations and produced | ||
// receipts on the server. | ||
const [res] = await connection.execute(invocation) | ||
|
||
if (res.out.error) { | ||
return res.out | ||
} | ||
return { | ||
ok: {}, | ||
} | ||
} | ||
} |
Oops, something went wrong.