Skip to content

Commit

Permalink
chor: appease formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
alanshaw committed Nov 4, 2024
1 parent b179910 commit d89a2a1
Show file tree
Hide file tree
Showing 27 changed files with 244 additions and 150 deletions.
2 changes: 1 addition & 1 deletion packages/access-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export type InvokeOptions<
Match<{ can: A; with: R & Resource; nb: Caveats }, UnknownMatch>
>
> = UCANBasicOptions &
Omit<InferInvokedCapability<CAP>, 'can'|'with'> & {
Omit<InferInvokedCapability<CAP>, 'can' | 'with'> & {
/**
* Resource for the capability, normally a Space DID
* Defaults to the current selected Space
Expand Down
10 changes: 4 additions & 6 deletions packages/capabilities/src/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ export const allocate = capability({
/** DID of the user space where the allocation takes place. */
space: SpaceDID,
}),
derives: (claimed, delegated) => (
derives: (claimed, delegated) =>
and(equalWith(claimed, delegated)) ||
and(equalBlob(claimed, delegated)) ||
and(checkLink(claimed.nb.cause, delegated.nb.cause, 'cause')) ||
and(equal(claimed.nb.space, delegated.nb.space, 'space')) ||
ok({})
),
ok({}),
})

/**
Expand All @@ -78,12 +77,11 @@ export const accept = capability({
/** This task is blocked on `http/put` receipt available */
_put: Await,
}),
derives: (claimed, delegated) => (
derives: (claimed, delegated) =>
and(equalWith(claimed, delegated)) ||
and(equalBlob(claimed, delegated)) ||
and(equal(claimed.nb.space, delegated.nb.space, 'space')) ||
ok({})
),
ok({}),
})

// ⚠️ We export imports here so they are not omitted in generated typedefs
Expand Down
8 changes: 6 additions & 2 deletions packages/capabilities/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,15 @@ export type BlobAllocate = InferInvokedCapability<typeof BlobCaps.allocate>
export type BlobAccept = InferInvokedCapability<typeof BlobCaps.accept>
export type SpaceBlob = InferInvokedCapability<typeof SpaceBlobCaps.blob>
export type SpaceBlobAdd = InferInvokedCapability<typeof SpaceBlobCaps.add>
export type SpaceBlobRemove = InferInvokedCapability<typeof SpaceBlobCaps.remove>
export type SpaceBlobRemove = InferInvokedCapability<
typeof SpaceBlobCaps.remove
>
export type SpaceBlobList = InferInvokedCapability<typeof SpaceBlobCaps.list>
export type SpaceBlobGet = InferInvokedCapability<typeof SpaceBlobCaps.get>
export type W3sBlob = InferInvokedCapability<typeof W3sBlobCaps.blob>
export type W3sBlobAllocate = InferInvokedCapability<typeof W3sBlobCaps.allocate>
export type W3sBlobAllocate = InferInvokedCapability<
typeof W3sBlobCaps.allocate
>
export type W3sBlobAccept = InferInvokedCapability<typeof W3sBlobCaps.accept>

export interface BlobModel {
Expand Down
50 changes: 27 additions & 23 deletions packages/capabilities/test/capabilities/blob.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {
mallory as account,
bob,
} from '../helpers/fixtures.js'
import { createCar, createCborCid, validateAuthorization } from '../helpers/utils.js'
import {
createCar,
createCborCid,
validateAuthorization,
} from '../helpers/utils.js'

const top = () =>
Capability.top.delegate({
Expand Down Expand Up @@ -38,10 +42,10 @@ describe('blob capabilities', function () {
nb: {
blob: {
digest: car.cid.multihash.bytes,
size: car.bytes.length
size: car.bytes.length,
},
space: space.did(),
cause: await createCborCid({ now: Date.now() })
cause: await createCborCid({ now: Date.now() }),
},
proofs: [await top()],
})
Expand All @@ -68,10 +72,10 @@ describe('blob capabilities', function () {
nb: {
blob: {
digest: car.cid.multihash.bytes,
size: car.bytes.length
size: car.bytes.length,
},
space: space.did(),
cause: await createCborCid({ now: Date.now() })
cause: await createCborCid({ now: Date.now() }),
},
proofs: [await blob()],
})
Expand Down Expand Up @@ -105,10 +109,10 @@ describe('blob capabilities', function () {
nb: {
blob: {
digest: car.cid.multihash.bytes,
size: car.bytes.length
size: car.bytes.length,
},
space: space.did(),
cause: await createCborCid({ now: Date.now() })
cause: await createCborCid({ now: Date.now() }),
},
proofs: [blob],
})
Expand All @@ -134,7 +138,7 @@ describe('blob capabilities', function () {
audience: bob,
with: account.did(),
nb: {
space: space0.did()
space: space0.did(),
},
proofs: [await top()],
})
Expand All @@ -146,10 +150,10 @@ describe('blob capabilities', function () {
nb: {
blob: {
digest: car.cid.multihash.bytes,
size: car.bytes.length
size: car.bytes.length,
},
space: space1.did(),
cause: await createCborCid({ now: Date.now() })
cause: await createCborCid({ now: Date.now() }),
},
proofs: [blob],
})
Expand All @@ -175,12 +179,12 @@ describe('blob capabilities', function () {
nb: {
blob: {
digest: car.cid.multihash.bytes,
size: car.bytes.length
size: car.bytes.length,
},
space: space.did(),
_put: {
'ucan/await': ['.out.ok', await createCborCid('receipt')]
}
'ucan/await': ['.out.ok', await createCborCid('receipt')],
},
},
proofs: [await top()],
})
Expand All @@ -207,12 +211,12 @@ describe('blob capabilities', function () {
nb: {
blob: {
digest: car.cid.multihash.bytes,
size: car.bytes.length
size: car.bytes.length,
},
space: space.did(),
_put: {
'ucan/await': ['.out.ok', await createCborCid('receipt')]
}
'ucan/await': ['.out.ok', await createCborCid('receipt')],
},
},
proofs: [await blob()],
})
Expand Down Expand Up @@ -246,12 +250,12 @@ describe('blob capabilities', function () {
nb: {
blob: {
digest: car.cid.multihash.bytes,
size: car.bytes.length
size: car.bytes.length,
},
space: space.did(),
_put: {
'ucan/await': ['.out.ok', await createCborCid('receipt')]
}
'ucan/await': ['.out.ok', await createCborCid('receipt')],
},
},
proofs: [blob],
})
Expand All @@ -277,7 +281,7 @@ describe('blob capabilities', function () {
audience: bob,
with: account.did(),
nb: {
space: space0.did()
space: space0.did(),
},
proofs: [await top()],
})
Expand All @@ -289,12 +293,12 @@ describe('blob capabilities', function () {
nb: {
blob: {
digest: car.cid.multihash.bytes,
size: car.bytes.length
size: car.bytes.length,
},
space: space1.did(),
_put: {
'ucan/await': ['.out.ok', await createCborCid('receipt')]
}
'ucan/await': ['.out.ok', await createCborCid('receipt')],
},
},
proofs: [blob],
})
Expand Down
8 changes: 6 additions & 2 deletions packages/filecoin-api/src/aggregator/buffer-reducing.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,17 @@ export function aggregatePieces(bufferedPieces, config) {
builder.offset * BigInt(NODE_SIZE) +
BigInt(builder.limit) * BigInt(Index.EntrySize)

console.log(`Used ${totalUsedSpace} bytes in ${addedBufferedPieces.length} pieces (min ${config.minAggregateSize} bytes)`)
console.log(
`Used ${totalUsedSpace} bytes in ${addedBufferedPieces.length} pieces (min ${config.minAggregateSize} bytes)`
)

// If not enough space return undefined
if (totalUsedSpace < BigInt(config.minAggregateSize)) {
// ...but only if not exceeded max aggregate pieces
if (addedBufferedPieces.length === config.maxAggregatePieces) {
console.warn(`Building aggregate: max allowed pieces reached (${config.maxAggregatePieces})`)
console.warn(
`Building aggregate: max allowed pieces reached (${config.maxAggregatePieces})`
)
} else {
return console.log('Not enough data for aggregate.')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/filecoin-api/src/aggregator/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export const handleAggregateInsertToPieceAcceptQueue = async (
const results = await map(
pieces,
/** @returns {Promise<import('@ucanto/interface').Result<import('@ucanto/interface').Unit, RangeError|import('../types.js').QueueAddError>>} */
async piece => {
async (piece) => {
const inclusionProof = aggregateBuilder.resolveProof(piece.link)
if (inclusionProof.error) return inclusionProof

Expand Down
6 changes: 4 additions & 2 deletions packages/filecoin-api/test/context/store-implementations.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export const getStoreImplementations = () => ({
queryFn: (items, search, options) => {
const results = Array.from(items)
.filter((i) => i.insertedAt > (options?.cursor ?? ''))
.filter((i) => search.status ? i.status === search.status : true)
.filter((i) =>
search.status ? i.status === search.status : true
)
.sort((a, b) => (a.insertedAt > b.insertedAt ? 1 : -1))
.slice(0, options?.size ?? items.size)
return { results, cursor: results.at(-1)?.insertedAt }
Expand Down Expand Up @@ -208,7 +210,7 @@ export const getStoreImplementations = () => ({
return nItem
},
})
),
)
),
},
dealTracker: {
Expand Down
5 changes: 4 additions & 1 deletion packages/filecoin-api/test/events/aggregator.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,10 @@ export const test = {
}))
)
assert.ok(handledMessageRes.ok)
assert.equal(handledMessageRes.ok?.aggregatedPieces, config.maxAggregatePieces)
assert.equal(
handledMessageRes.ok?.aggregatedPieces,
config.maxAggregatePieces
)

await pWaitFor(
() =>
Expand Down
12 changes: 7 additions & 5 deletions packages/upload-api/src/blob/accept.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export const poll = async (context, receipt) => {
space: allocate.nb.space,
_put: {
'ucan/await': ['.out.ok', receipt.ran.link()],
}
}
},
},
}),
{
// ⚠️ We need invocation to be deterministic which is why we use exact
Expand All @@ -77,17 +77,19 @@ export const poll = async (context, receipt) => {
return configure
}

const acceptReceipt = await configure.ok.invocation.execute(configure.ok.connection)
const acceptReceipt = await configure.ok.invocation.execute(
configure.ok.connection
)

// record the invocation and the receipt
const message = await Message.build({
invocations: [configure.ok.invocation],
receipts: [acceptReceipt]
receipts: [acceptReceipt],
})
const messageWrite = await context.agentStore.messages.write({
source: await Transport.outbound.encode(message),
data: message,
index: [...AgentMessage.index(message)]
index: [...AgentMessage.index(message)],
})
if (messageWrite.error) {
return messageWrite
Expand Down
16 changes: 10 additions & 6 deletions packages/upload-api/src/blob/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,13 @@ async function allocate({ context, blob, space, cause }) {
size: blob.size,
},
space,
cause
}
cause,
},
})

const configure = await router.configureInvocation(candidate.ok, cap, { expiration: Infinity })
const configure = await router.configureInvocation(candidate.ok, cap, {
expiration: Infinity,
})
if (configure.error) {
return configure
}
Expand All @@ -149,12 +151,12 @@ async function allocate({ context, blob, space, cause }) {
// get a http/put receipt in ucan/conclude
const message = await Message.build({
invocations: [configure.ok.invocation],
receipts: [receipt]
receipts: [receipt],
})
const messageWrite = await context.agentStore.messages.write({
source: await Transport.outbound.encode(message),
data: message,
index: [...AgentMessage.index(message)]
index: [...AgentMessage.index(message)],
})
if (messageWrite.error) {
return messageWrite
Expand Down Expand Up @@ -280,7 +282,9 @@ async function accept({ context, provider, blob, space, delivery }) {
},
})

const configure = await context.router.configureInvocation(provider, cap, { expiration: Infinity })
const configure = await context.router.configureInvocation(provider, cap, {
expiration: Infinity,
})
if (configure.error) {
return configure
}
Expand Down
9 changes: 7 additions & 2 deletions packages/upload-api/src/index/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,20 @@ const add = async ({ capability }, context) => {
// ensure indexed shards are allocated in the agent's space
const shardDigests = [...idxRes.ok.shards.keys()]
const shardAllocRes = await Promise.all(
shardDigests.map((s) => assertRegistered(context, space, s, 'ShardNotFound'))
shardDigests.map((s) =>
assertRegistered(context, space, s, 'ShardNotFound')
)
)
for (const res of shardAllocRes) {
if (res.error) return res
}

// TODO: randomly validate slices in the index correspond to slices in the blob

const publishRes = await publishIndexClaim(context, { content: idxRes.ok.content, index: idxLink })
const publishRes = await publishIndexClaim(context, {
content: idxRes.ok.content,
index: idxLink,
})
if (publishRes.error) {
return publishRes
}
Expand Down
4 changes: 1 addition & 3 deletions packages/upload-api/src/provider-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ export const add = async (
}
}
const accountMailtoDID =
/** @type {import('@storacha/did-mailto/types').DidMailto} */ (
accountDID
)
/** @type {import('@storacha/did-mailto/types').DidMailto} */ (accountDID)
const rateLimitResult = await ensureRateLimitAbove(
rateLimits,
[mailtoDidToDomain(accountMailtoDID), mailtoDidToEmail(accountMailtoDID)],
Expand Down
Loading

0 comments on commit d89a2a1

Please sign in to comment.