-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Capability definitions to allow clients to check for inclusion of cid in store shards or upload roots. Also allows client to fetch the additional properties we store. This will, for example, let a client verify all shards for an upload have been removed before removing an upload. _I'm aiming to simplify things with this PR so that we return insertedAt info on the Upload/Store ListItem types, and return the same object shape for a single object get. If this is pleasing, then I will continue in this direction and make Remove also return the same shape if it removes something_ TODO: - [x] spec update storacha/specs#82 - [x] tests License: MIT --------- Signed-off-by: Oli Evans <[email protected]> Co-authored-by: Alan Shaw <[email protected]>
- Loading branch information
Showing
21 changed files
with
342 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as Server from '@ucanto/server' | ||
import * as Store from '@web3-storage/capabilities/store' | ||
import * as API from '../types.js' | ||
|
||
/** | ||
* @param {API.StoreServiceContext} context | ||
* @returns {API.ServiceMethod<API.StoreGet, API.StoreGetSuccess, API.StoreGetFailure>} | ||
*/ | ||
export function storeGetProvider(context) { | ||
return Server.provide(Store.get, async ({ capability }) => { | ||
const { link } = capability.nb | ||
if (!link) { | ||
return Server.fail('nb.link must be set') | ||
} | ||
const space = Server.DID.parse(capability.with).did() | ||
const res = await context.storeTable.get(space, link) | ||
if (!res) { | ||
return { | ||
error: { | ||
name: 'StoreItemNotFound', | ||
message: 'Store item not found', | ||
}, | ||
} | ||
} | ||
return { | ||
ok: res, | ||
} | ||
}) | ||
} |
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 * as Server from '@ucanto/server' | ||
import * as Upload from '@web3-storage/capabilities/upload' | ||
import * as API from '../types.js' | ||
|
||
/** | ||
* @param {API.UploadServiceContext} context | ||
* @returns {API.ServiceMethod<API.UploadGet, API.UploadGetSuccess, API.UploadGetFailure>} | ||
*/ | ||
export function uploadGetProvider(context) { | ||
return Server.provide(Upload.get, async ({ capability }) => { | ||
const { root } = capability.nb | ||
if (!root) { | ||
return Server.fail('nb.root must be set') | ||
} | ||
const space = Server.DID.parse(capability.with).did() | ||
const res = await context.uploadTable.get(space, root) | ||
if (!res) { | ||
return { | ||
error: { | ||
name: 'UploadNotFound', | ||
message: 'Upload not found', | ||
}, | ||
} | ||
} | ||
return { | ||
ok: res, | ||
} | ||
}) | ||
} |
Oops, something went wrong.