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

chore: update upload-api dependency #2

Merged
merged 4 commits into from
Nov 12, 2024
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
5 changes: 4 additions & 1 deletion billing/lib/ucan-stream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as ServiceBlobCaps from '@storacha/capabilities/blob'
import * as BlobCaps from '@storacha/capabilities/space/blob'
import * as StoreCaps from '@storacha/capabilities/store'
import * as DID from '@ipld/dag-ucan/did'

/**
* Filters UCAN stream messages that are receipts for invocations that alter
Expand All @@ -20,7 +21,9 @@ export const findSpaceUsageDeltas = messages => {
/** @type {number|undefined} */
let size
if (isReceiptForCapability(message, ServiceBlobCaps.allocate) && isServiceBlobAllocateSuccess(message.out)) {
resource = message.value.att[0].nb?.space
const spaceDigestBytes = message.value.att[0].nb?.space
if (!spaceDigestBytes) throw new Error('missing space in allocate caveats')
resource = DID.decode(spaceDigestBytes).did()
size = message.out.ok.size
} else if (isReceiptForCapability(message, BlobCaps.remove) && isBlobRemoveSuccess(message.out)) {
resource = /** @type {import('@ucanto/interface').DID} */ (message.value.att[0].with)
Expand Down
1 change: 1 addition & 0 deletions billing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@aws-sdk/client-dynamodb": "^3.515.0",
"@aws-sdk/client-sqs": "^3.515.0",
"@aws-sdk/util-dynamodb": "^3.515.0",
"@ipld/dag-ucan": "^3.4.0",
"@sentry/serverless": "^7.74.1",
"@storacha/capabilities": "^1.0.0",
"@ucanto/interface": "^10.0.1",
Expand Down
5 changes: 3 additions & 2 deletions billing/test/lib/ucan-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Schema } from '@ucanto/core'
import * as ServiceBlobCaps from '@storacha/capabilities/blob'
import * as BlobCaps from '@storacha/capabilities/space/blob'
import * as StoreCaps from '@storacha/capabilities/store'
import * as DID from '@ipld/dag-ucan/did'
import { findSpaceUsageDeltas, storeSpaceUsageDeltas } from '../../lib/ucan-stream.js'
import { randomConsumer } from '../helpers/consumer.js'
import { randomLink } from '../helpers/dag.js'
Expand Down Expand Up @@ -49,7 +50,7 @@ export const test = {
size: 138
},
cause: randomLink(),
space: await randomDIDKey()
space: DID.parse(await randomDIDKey())
}
}],
aud: await randomDID(),
Expand Down Expand Up @@ -120,7 +121,7 @@ export const test = {
d.cause.toString() === r.invocationCid.toString() &&
// resource for blob allocate is found in the caveats
(r.value.att[0].can === ServiceBlobCaps.allocate.can
? d.resource === r.value.att[0].nb.space
? d.resource === DID.decode(r.value.att[0].nb.space).did()
: d.resource === r.value.att[0].with)
)))
}
Expand Down
20 changes: 11 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions upload-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"@ipld/dag-ucan": "^3.0.1",
"@sentry/serverless": "^7.74.1",
"@storacha/access": "^0.0.0",
"@storacha/capabilities": "^1.0.0",
"@storacha/capabilities": "^1.1.1",
"@storacha/did-mailto": "^1.0.0",
"@storacha/indexing-service-client": "^1.1.2",
"@storacha/upload-api": "^1.1.2",
"@storacha/upload-api": "^1.1.3",
"@ucanto/client": "^9.0.1",
"@ucanto/core": "^10.0.1",
"@ucanto/interface": "^10.0.1",
Expand Down
13 changes: 7 additions & 6 deletions upload-api/stores/blob-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ok, error } from '@ucanto/core'
import { EntryNotFound, EntryExists } from '@storacha/upload-api/blob'
import { base58btc } from 'multiformats/bases/base58'
import * as Link from 'multiformats/link'
import * as Digest from 'multiformats/hashes/digest'
import { getDynamoClient } from '../../lib/aws/dynamo.js'
import { METRICS_NAMES, SPACE_METRICS_NAMES } from '../constants.js'

Expand Down Expand Up @@ -56,19 +57,19 @@ export const useBlobRegistry = (dynamoDb, tableName, metrics) => ({
const raw = unmarshall(response.Item)
return ok({
blob: {
digest: base58btc.decode(raw.digest),
digest: Digest.decode(base58btc.decode(raw.digest)),
size: raw.size
},
cause: Link.parse(raw.cause).toV1(),
insertedAt: raw.insertedAt
insertedAt: new Date(raw.insertedAt)
})
},

/** @type {BlobAPI.Registry['register']} */
register: async ({ space, blob, cause }) => {
const item = {
space,
digest: base58btc.encode(blob.digest),
digest: base58btc.encode(blob.digest.bytes),
size: blob.size,
cause: cause.toString(),
insertedAt: new Date().toISOString(),
Expand Down Expand Up @@ -162,7 +163,7 @@ export const useBlobRegistry = (dynamoDb, tableName, metrics) => ({

const results =
response.Items?.map((i) => toEntry(unmarshall(i))) ?? []
const firstDigest = results[0] ? base58btc.encode(results[0].blob.digest) : undefined
const firstDigest = results[0] ? base58btc.encode(results[0].blob.digest.bytes) : undefined
// Get cursor of the item where list operation stopped (inclusive).
// This value can be used to start a new operation to continue listing.
const lastKey =
Expand Down Expand Up @@ -191,9 +192,9 @@ export const useBlobRegistry = (dynamoDb, tableName, metrics) => ({
* @returns {BlobAPI.Entry}
*/
export const toEntry = ({ digest, size, cause, insertedAt }) => ({
blob: { digest: base58btc.decode(digest), size },
blob: { digest: Digest.decode(base58btc.decode(digest)), size },
cause: Link.parse(cause).toV1(),
insertedAt,
insertedAt: new Date(insertedAt),
})

/**
Expand Down
Loading