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

refactor: add cause as a param to deregister #136

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions packages/upload-api/src/blob/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as API from '../types.js'
* @returns {API.ServiceMethod<API.SpaceBlobRemove, API.SpaceBlobRemoveSuccess, API.SpaceBlobRemoveFailure>}
*/
export function blobRemoveProvider(context) {
return Server.provide(SpaceBlob.remove, async ({ capability }) => {
return Server.provide(SpaceBlob.remove, async ({ capability, invocation }) => {
const space = capability.with
const digest = Digest.decode(capability.nb.digest)

Expand All @@ -20,7 +20,7 @@ export function blobRemoveProvider(context) {
return exists
}

const dereg = await context.registry.deregister(space, digest)
const dereg = await context.registry.deregister({space, digest, cause: invocation.link()})
if (dereg.error) {
// unlikely as we just found it...but possible I guess
if (dereg.error.name === 'EntryNotFound') {
Expand Down
11 changes: 7 additions & 4 deletions packages/upload-api/src/types/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ export interface Registry {
options?: ListOptions
) => Promise<Result<ListResponse<Entry>, Failure>>
/** Removes an item from the registry if it exists. */
deregister: (
space: SpaceDID,
digest: MultihashDigest
) => Promise<Result<Unit, EntryNotFound>>
deregister: (item: DeregistrationData) => Promise<Result<Unit, EntryNotFound>>
}

export interface ListOptions {
Expand All @@ -76,6 +73,12 @@ export interface BlobModel {
size: number
}

export interface DeregistrationData {
space: SpaceDID,
digest: MultihashDigest,
cause: Link
}

export interface RegistrationData {
space: SpaceDID
cause: Link
Expand Down
6 changes: 4 additions & 2 deletions packages/upload-api/test/storage/blob-registry-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ export const test = {
const { registry } = context
const data = new Uint8Array([11, 22, 34, 44, 55])
const digest = await sha256.digest(data)
const dereg = await registry.deregister(space, digest)
const cause = await randomCID()
const dereg = await registry.deregister({space, digest, cause})
assert.ok(dereg.error)
assert.equal(dereg.error?.name, EntryNotFound.name)
},
Expand All @@ -155,7 +156,8 @@ export const test = {
const find0 = await registry.find(space, digest)
assert.ok(find0.ok)

const dereg = await registry.deregister(space, digest)
const deregCause = await randomCID()
const dereg = await registry.deregister({space, digest, cause: deregCause})
assert.ok(dereg.ok)

const find1 = await registry.find(space, digest)
Expand Down
2 changes: 1 addition & 1 deletion packages/upload-api/test/storage/blob-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Registry {
}

/** @type {API.BlobAPI.Registry['deregister']} */
async deregister(space, digest) {
async deregister({space, digest, cause}) {
const entries = this.data.get(space) ?? []
const entry = entries.find((e) => equals(e.blob.digest.bytes, digest.bytes))
if (!entry) return error(new EntryNotFound())
Expand Down