Skip to content

Commit

Permalink
chore: updates based on specs pr review
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Aug 8, 2023
1 parent 8dca776 commit aa260f3
Show file tree
Hide file tree
Showing 28 changed files with 325 additions and 327 deletions.
48 changes: 22 additions & 26 deletions packages/capabilities/src/filecoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ export const filecoinAdd = capability({
})

/**
* `piece/add` capability allows agent to add a piece piece to be aggregated
* `aggregate/add` capability allows agent to add a piece to be aggregated
* so that it can be stored by a Storage provider on a future time.
*/
export const pieceAdd = capability({
can: 'piece/add',
export const aggregateAdd = capability({
can: 'aggregate/add',
/**
* did:key identifier of the broker authority where offer is made available.
*/
Expand Down Expand Up @@ -95,18 +95,19 @@ export const pieceAdd = capability({
return (
and(equalWith(claim, from)) ||
and(checkLink(claim.nb.piece, from.nb.piece, 'nb.piece')) ||
and(equal(claim.nb.storefront, from.nb.storefront, 'nb.storefront')) ||
and(equal(claim.nb.group, from.nb.group, 'nb.group')) ||
ok({})
)
},
})

/**
* `aggregate/add` capability allows agent to create an offer to get an aggregate
* `deal/add` capability allows agent to create a deal offer to get an aggregate
* of CARs files in the market to be fetched and stored by a Storage provider.
*/
export const aggregateAdd = capability({
can: 'aggregate/add',
export const dealAdd = capability({
can: 'deal/add',
/**
* did:key identifier of the broker authority where offer is made available.
*/
Expand All @@ -116,12 +117,12 @@ export const aggregateAdd = capability({
* CID of the DAG-CBOR encoded block with offer details.
* Service will queue given offer to be validated and handled.
*/
offer: Schema.link(),
pieces: Schema.link(),
/**
* Commitment proof for the aggregate being offered.
* https://github.com/filecoin-project/go-state-types/blob/1e6cf0d47cdda75383ef036fc2725d1cf51dbde8/abi/piece.go#L47-L50
*/
piece: /** @type {import('./types').PieceLinkSchema} */ (
aggregate: /** @type {import('./types').PieceLinkSchema} */ (
Schema.link({
code: FilCommitmentUnsealed,
version: 1,
Expand All @@ -131,38 +132,33 @@ export const aggregateAdd = capability({
})
),
/**
* Necessary fields for a Filecoin Deal proposal.
* Storefront requesting deal
*/
deal: Schema.struct({
/**
* with tenantId broker can select one of their configured wallets
*/
tenantId: Schema.text(),
/**
* arbitrary label to be added to the deal on chain
*/
label: Schema.text().optional(),
}),
storefront: Schema.text(),
/**
* arbitrary label to be added to the deal on chain
*/
label: Schema.text().optional(),
}),
derives: (claim, from) => {
return (
and(equalWith(claim, from)) ||
and(checkLink(claim.nb.offer, from.nb.offer, 'nb.offer')) ||
and(checkLink(claim.nb.piece, from.nb.piece, 'nb.piece')) ||
and(checkLink(claim.nb.aggregate, from.nb.aggregate, 'nb.aggregate')) ||
and(checkLink(claim.nb.pieces, from.nb.pieces, 'nb.pieces')) ||
and(
equal(claim.nb.deal.tenantId, from.nb.deal.tenantId, 'nb.deal.tenantId')
equal(claim.nb.storefront, from.nb.storefront, 'nb.storefront')
) ||
and(equal(claim.nb.deal.label, from.nb.deal.label, 'nb.deal.label')) ||
and(equal(claim.nb.label, from.nb.label, 'nb.label')) ||
ok({})
)
},
})

/**
* `chain/info` capability allows agent to get chain info of a given piece.
* `chain-tracker/info` capability allows agent to get chain info of a given piece.
*/
export const chainInfo = capability({
can: 'chain/info',
export const chainTrackerInfo = capability({
can: 'chain-tracker/info',
/**
* did:key identifier of the broker authority where offer is made available.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/capabilities/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const abilitiesAsStrings = [
Access.authorize.can,
Access.session.can,
Filecoin.filecoinAdd.can,
Filecoin.pieceAdd.can,
Filecoin.aggregateAdd.can,
Filecoin.chainInfo.can,
Filecoin.dealAdd.can,
Filecoin.chainTrackerInfo.can,
]
45 changes: 21 additions & 24 deletions packages/capabilities/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,53 +76,50 @@ export type SpaceRecoverValidation = InferInvokedCapability<
export type SpaceRecover = InferInvokedCapability<typeof recover>

// filecoin
export type QUEUE_STATUS = 'queued' | 'accepted' | 'rejected'
export type FILECOIN_PROCESSING_STATUS = 'pending' | 'done'
export interface FilecoinAddSuccess {
status: QUEUE_STATUS
piece: PieceLink
}
export interface FilecoinAddFailure extends Ucanto.Failure {
reason: string
name: string
}

export interface PieceAddSuccess {
status: QUEUE_STATUS
export interface AggregateAddSuccess {
piece: PieceLink
aggregate?: PieceLink
}
export interface PieceAddFailure extends Ucanto.Failure {
reason: string
export interface AggregateAddFailure extends Ucanto.Failure {
name: string
}

export interface AggregateAddSuccess {
status: QUEUE_STATUS
piece?: PieceLink
export interface DealAddSuccess {
aggregate?: PieceLink
}

export type AggregateAddFailure =
| AggregateAddParseFailure
| AggregateAddFailureWithBadPiece
export type DealAddFailure =
| DealAddParseFailure
| DealAddFailureWithBadPiece

export interface AggregateAddParseFailure extends Ucanto.Failure {
reason: string
export interface DealAddParseFailure extends Ucanto.Failure {
name: string
}

export interface AggregateAddFailureWithBadPiece extends Ucanto.Failure {
export interface DealAddFailureWithBadPiece extends Ucanto.Failure {
piece?: PieceLink
cause?: AggregateAddFailureCause[] | unknown
cause?: DealAddFailureCause[] | unknown
}

export interface AggregateAddFailureCause {
export interface DealAddFailureCause {
piece: PieceLink
reason: string
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ChainInfoSuccess {
export interface ChainTrackerInfoSuccess {
// TODO
}

export interface ChainInfoFailure extends Ucanto.Failure {
export interface ChainTrackerInfoFailure extends Ucanto.Failure {
// TODO
}

Expand All @@ -143,11 +140,11 @@ export type StoreList = InferInvokedCapability<typeof list>
export type FilecoinAdd = InferInvokedCapability<
typeof FilecoinCaps.filecoinAdd
>
export type PieceAdd = InferInvokedCapability<typeof FilecoinCaps.pieceAdd>
export type AggregateAdd = InferInvokedCapability<
typeof FilecoinCaps.aggregateAdd
>
export type ChainInfo = InferInvokedCapability<typeof FilecoinCaps.chainInfo>
export type DealAdd = InferInvokedCapability<typeof FilecoinCaps.dealAdd>
export type ChainTrackerInfo = InferInvokedCapability<typeof FilecoinCaps.chainTrackerInfo>
// Top
export type Top = InferInvokedCapability<typeof top>

Expand All @@ -174,7 +171,7 @@ export type AbilitiesArray = [
AccessAuthorize['can'],
AccessSession['can'],
FilecoinAdd['can'],
PieceAdd['can'],
AggregateAdd['can'],
ChainInfo['can']
DealAdd['can'],
ChainTrackerInfo['can']
]
20 changes: 10 additions & 10 deletions packages/filecoin-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"aggregator": [
"dist/src/aggregator.d.ts"
],
"broker": [
"dist/src/broker.d.ts"
"dealer": [
"dist/src/dealer.d.ts"
],
"chain": [
"dist/src/chain.d.ts"
"chain-tracker": [
"dist/src/chain-tracker.d.ts"
],
"errors": [
"dist/src/errors.d.ts"
Expand Down Expand Up @@ -50,13 +50,13 @@
"types": "./dist/src/aggregator.d.ts",
"import": "./src/aggregator.js"
},
"./broker": {
"types": "./dist/src/broker.d.ts",
"import": "./src/broker.js"
"./dealer": {
"types": "./dist/src/dealer.d.ts",
"import": "./src/dealer.js"
},
"./chain": {
"types": "./dist/src/chain.d.ts",
"import": "./src/chain.js"
"./chain-tracker": {
"types": "./dist/src/chain-tracker.d.ts",
"import": "./src/chain-tracker.js"
},
"./storefront": {
"types": "./dist/src/storefront.d.ts",
Expand Down
16 changes: 7 additions & 9 deletions packages/filecoin-api/src/aggregator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import * as API from './types.js'
import { QueueOperationFailed, StoreOperationFailed } from './errors.js'

/**
* @param {API.Input<FilecoinCapabilities.pieceAdd>} input
* @param {API.Input<FilecoinCapabilities.aggregateAdd>} input
* @param {API.AggregatorServiceContext} context
* @returns {Promise<API.UcantoInterface.Result<API.PieceAddSuccess, API.PieceAddFailure> | API.UcantoInterface.JoinBuilder<API.PieceAddSuccess>>}
* @returns {Promise<API.UcantoInterface.Result<API.AggregateAddSuccess, API.AggregateAddFailure> | API.UcantoInterface.JoinBuilder<API.AggregateAddSuccess>>}
*/
export const claim = async ({ capability }, context) => {
const { piece, storefront, group } = capability.nb
Expand All @@ -26,7 +26,7 @@ export const claim = async ({ capability }, context) => {
* @param {string} storefront
* @param {string} group
* @param {API.AggregatorServiceContext} context
* @returns {Promise<API.UcantoInterface.Result<API.PieceAddSuccess, API.PieceAddFailure> | API.UcantoInterface.JoinBuilder<API.PieceAddSuccess>>}
* @returns {Promise<API.UcantoInterface.Result<API.AggregateAddSuccess, API.AggregateAddFailure> | API.UcantoInterface.JoinBuilder<API.AggregateAddSuccess>>}
*/
async function queueAdd(piece, storefront, group, context) {
const queued = await context.addQueue.add({
Expand All @@ -42,7 +42,7 @@ async function queueAdd(piece, storefront, group, context) {
}

// Create effect for receipt
const fx = await FilecoinCapabilities.pieceAdd
const fx = await FilecoinCapabilities.aggregateAdd
.invoke({
issuer: context.id,
audience: context.id,
Expand All @@ -56,7 +56,6 @@ async function queueAdd(piece, storefront, group, context) {
.delegate()

return Server.ok({
status: /** @type {API.QUEUE_STATUS} */ ('queued'),
piece,
}).join(fx.link())
}
Expand All @@ -66,7 +65,7 @@ async function queueAdd(piece, storefront, group, context) {
* @param {string} storefront
* @param {string} group
* @param {API.AggregatorServiceContext} context
* @returns {Promise<API.UcantoInterface.Result<API.PieceAddSuccess, API.PieceAddFailure> | API.UcantoInterface.JoinBuilder<API.PieceAddSuccess>>}
* @returns {Promise<API.UcantoInterface.Result<API.AggregateAddSuccess, API.AggregateAddFailure> | API.UcantoInterface.JoinBuilder<API.AggregateAddSuccess>>}
*/
async function queueHandler(piece, storefront, group, context) {
const put = await context.pieceStore.put({
Expand All @@ -84,7 +83,6 @@ async function queueHandler(piece, storefront, group, context) {

return {
ok: {
status: 'accepted',
piece,
},
}
Expand All @@ -95,9 +93,9 @@ async function queueHandler(piece, storefront, group, context) {
*/
export function createService(context) {
return {
piece: {
aggregate: {
add: Server.provideAdvanced({
capability: FilecoinCapabilities.pieceAdd,
capability: FilecoinCapabilities.aggregateAdd,
handler: (input) => claim(input, context),
}),
},
Expand Down
Loading

0 comments on commit aa260f3

Please sign in to comment.