forked from storacha/w3up
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: return allocated bytes in
store/add
receipt (storacha#1213)
This PR adds a new field to the `store/add` success result: `allocated: number` - the total bytes allocated in the space to accommodate the stored item, it **may be zero if the item is _already_ stored in _this_ space**. This allows us to accurately report and bill for items stored in a space. Currently, `store/add` when the item is already stored in the space will cause a new diff to be created, effecitvely counting the same shard multiple times. This could happen because of accidentally uploading the same item, or because of a retry of a big item where some shards were successful. The following additional changes enable this functionality: * `StoreTable` and `UploadTable` methods now have return types that are `Result<O, X>` - this allows us to specify and communicate 2 errors `RecordNotFound` and `RecordKeyConflict` (explained in the following bullets). * In the context of these 2 tables the semantics of `insert` have changed to be more in line with postgres/other DBs - "insert" means add to the DB or fail (with `RecordKeyConflict`) if an item with the same key already exists. * We can satisfy this constraint in dynamodb with [condition expressions](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ConditionExpressions.html#Expressions.ConditionExpressions.PreventingOverwrites) or [`ReturnValues`](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html#DDB-PutItem-request-ReturnValues). * In the `UploadTable` I've renamed `insert` to `upsert` since the behaviour in use here is more akin to "update or insert" - aka ["upsert"](https://en.wiktionary.org/wiki/upsert). * `remove` and `get` now fail with `RecordNotFound` if the item to delete is not available. * Again in dynamodb we can satisfy this constraint with condition expressions or `ReturnValues` --------- Co-authored-by: Vasco Santos <santos.vasco10@gmail.com>
- Loading branch information
1 parent
4adca28
commit 5d52e44
Showing
26 changed files
with
424 additions
and
249 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
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
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,29 @@ | ||
import { Failure } from '@ucanto/server' | ||
|
||
export class StoreItemNotFound extends Failure { | ||
/** | ||
* @param {import('@ucanto/interface').DID} space | ||
* @param {import('@ucanto/interface').UnknownLink} link | ||
*/ | ||
constructor(space, link) { | ||
super() | ||
this.space = space | ||
this.link = link | ||
} | ||
|
||
get name() { | ||
return 'StoreItemNotFound' | ||
} | ||
|
||
describe() { | ||
return `${this.link} not found in ${this.space}` | ||
} | ||
|
||
toJSON() { | ||
return { | ||
...super.toJSON(), | ||
space: this.space, | ||
link: { '/': this.link.toString() }, | ||
} | ||
} | ||
} |
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
Oops, something went wrong.