Skip to content

Commit

Permalink
fix: allocation interface rename invocation to cause (#1382)
Browse files Browse the repository at this point in the history
Per
storacha/w3infra#353 (comment)
renaming this to cause so that it is transparent for the infra side what
this is: i.e. can be invocation or receipt
  • Loading branch information
vasco-santos authored Apr 18, 2024
1 parent 086759d commit 2d13042
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/upload-api/src/blob/allocate.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function blobAllocateProvider(context) {
const allocationInsert = await context.allocationsStorage.insert({
space,
blob,
invocation: cause,
cause,
})
if (allocationInsert.error) {
// if the insert failed with conflict then this item has already been
Expand Down
6 changes: 3 additions & 3 deletions packages/upload-api/src/types/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ export interface BlobModel {

export interface BlobAddInput {
space: DID
invocation: UnknownLink
cause: UnknownLink
blob: BlobModel
}

export interface BlobAddOutput
extends Omit<BlobAddInput, 'space' | 'invocation'> {}
extends Omit<BlobAddInput, 'space' | 'cause'> {}

export interface BlobGetOutput {
blob: { digest: Uint8Array; size: number }
invocation: UnknownLink
cause: UnknownLink
}

export interface BlobsStorage {
Expand Down
32 changes: 14 additions & 18 deletions packages/upload-api/test/storage/allocations-storage-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ export const test = {
},
proofs: [proof],
})
const invocation = (await blobAdd.delegate()).link()

const cause = (await blobAdd.delegate()).link()
const allocationInsert = await allocationsStorage.insert({
space: spaceDid,
blob: {
digest,
size,
},
invocation,
cause,
})

assert.ok(allocationInsert.ok)
Expand Down Expand Up @@ -72,15 +71,14 @@ export const test = {
},
proofs: [proof],
})
const invocation = (await blobAdd.delegate()).link()

const cause = (await blobAdd.delegate()).link()
const allocationInsert0 = await allocationsStorage.insert({
space: spaceDid,
blob: {
digest,
size,
},
invocation,
cause,
})
assert.ok(allocationInsert0.ok)

Expand All @@ -90,7 +88,7 @@ export const test = {
digest,
size,
},
invocation,
cause,
})
assert.ok(allocationInsert1.error)
assert.equal(allocationInsert1.error?.name, RecordKeyConflictName)
Expand Down Expand Up @@ -121,15 +119,14 @@ export const test = {
},
proofs: [proof],
})
const invocation = (await blobAdd.delegate()).link()

const cause = (await blobAdd.delegate()).link()
const allocationInsert = await allocationsStorage.insert({
space: spaceDid,
blob: {
digest,
size,
},
invocation,
cause,
})

assert.ok(allocationInsert.ok)
Expand All @@ -142,7 +139,7 @@ export const test = {
assert.ok(
equals(digest, allocationGet1.ok?.blob.digest || new Uint8Array())
)
assert.ok(allocationGet1.ok?.invocation)
assert.ok(allocationGet1.ok?.cause)
},
'should verify allocations exist': async (assert, context) => {
const { proof, spaceDid } = await registerSpace(alice, context)
Expand Down Expand Up @@ -170,15 +167,14 @@ export const test = {
},
proofs: [proof],
})
const invocation = (await blobAdd.delegate()).link()

const cause = (await blobAdd.delegate()).link()
const allocationInsert = await allocationsStorage.insert({
space: spaceDid,
blob: {
digest,
size,
},
invocation,
cause,
})

assert.ok(allocationInsert.ok)
Expand Down Expand Up @@ -240,7 +236,7 @@ export const test = {
const aliceAllocationInsert0 = await allocationsStorage.insert({
space: aliceSpaceDid,
blob: blob0,
invocation: aliceInvocation,
cause: aliceInvocation,
})
assert.ok(aliceAllocationInsert0.ok)

Expand All @@ -254,13 +250,13 @@ export const test = {
},
proofs: [bobProof],
})
const invocation = (await bobBlobAdd.delegate()).link()
const cause = (await bobBlobAdd.delegate()).link()

// Add bob allocations
const bobAllocationInsert = await allocationsStorage.insert({
space: bobSpaceDid,
blob: blob1,
invocation,
cause,
})
assert.ok(bobAllocationInsert.ok)

Expand Down Expand Up @@ -291,7 +287,7 @@ export const test = {
const aliceAllocationInsert1 = await allocationsStorage.insert({
space: aliceSpaceDid,
blob: blob1,
invocation: aliceInvocation1,
cause: aliceInvocation1,
})
assert.ok(aliceAllocationInsert1.ok)

Expand Down
4 changes: 2 additions & 2 deletions packages/upload-api/test/storage/allocations-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class AllocationsStorage {
* @param {Types.BlobAddInput} input
* @returns {ReturnType<Types.AllocationsStorage['insert']>}
*/
async insert({ space, invocation, ...output }) {
async insert({ space, cause, ...output }) {
if (
this.items.some(
(i) => i.space === space && equals(i.blob.digest, output.blob.digest)
Expand All @@ -27,7 +27,7 @@ export class AllocationsStorage {
}
this.items.unshift({
space,
invocation,
cause,
...output,
insertedAt: new Date().toISOString(),
})
Expand Down

0 comments on commit 2d13042

Please sign in to comment.