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!: add blob list and remove (storacha#1385)
Implements storacha/specs#123 BREAKING CHANGE: allocations storage interface now requires remove to be implemented
- Loading branch information
1 parent
1114383
commit 2f69946
Showing
14 changed files
with
593 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as Server from '@ucanto/server' | ||
import * as Blob from '@web3-storage/capabilities/blob' | ||
import * as API from '../types.js' | ||
|
||
/** | ||
* @param {API.BlobServiceContext} context | ||
* @returns {API.ServiceMethod<API.BlobList, API.BlobListSuccess, API.Failure>} | ||
*/ | ||
export function blobListProvider(context) { | ||
return Server.provide(Blob.list, async ({ capability }) => { | ||
const space = capability.with | ||
const { cursor, size } = capability.nb | ||
return await context.allocationsStorage.list(space, { size, cursor }) | ||
}) | ||
} |
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,26 @@ | ||
import * as Server from '@ucanto/server' | ||
import * as Blob from '@web3-storage/capabilities/blob' | ||
import * as API from '../types.js' | ||
|
||
import { RecordNotFoundErrorName } from '../errors.js' | ||
|
||
/** | ||
* @param {API.BlobServiceContext} context | ||
* @returns {API.ServiceMethod<API.BlobRemove, API.BlobRemoveSuccess, API.BlobRemoveFailure>} | ||
*/ | ||
export function blobRemoveProvider(context) { | ||
return Server.provide(Blob.remove, async ({ capability }) => { | ||
const space = capability.with | ||
const { digest } = capability.nb | ||
const res = await context.allocationsStorage.remove(space, digest) | ||
if (res.error && res.error.name === RecordNotFoundErrorName) { | ||
return { | ||
ok: { | ||
size: 0, | ||
}, | ||
} | ||
} | ||
|
||
return 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
Oops, something went wrong.