Skip to content

Commit

Permalink
feat: add w3up-client upload-client blob boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
joaosa committed May 8, 2024
1 parent f9c4043 commit 5196f9c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/upload-client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as UnixFS from './unixfs.js'
import * as CAR from './car.js'
import { ShardingStream, defaultFileComparator } from './sharding.js'

export { Store, Upload, UnixFS, CAR }
export { Blob, Store, Upload, UnixFS, CAR }
export * from './sharding.js'

/**
Expand Down
43 changes: 43 additions & 0 deletions packages/w3up-client/src/capability/blob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Blob } from '@web3-storage/upload-client'
import { Blob as BlobCapabilities } from '@web3-storage/capabilities'
import { Base } from '../base.js'

/**
* Client for interacting with the `blob/*` capabilities.
*/
export class BlobClient extends Base {
/**
* Store a DAG encoded as a CAR file.
*
* @param {Blob} car - CAR file data.
* @param {import('../types.js').RequestOptions} [options]
*/
async add(car, options = {}) {
const conf = await this._invocationConfig([BlobCapabilities.add.can])
options.connection = this._serviceConf.upload
return Blob.add(conf, car, options)
}

/**
* List CAR files stored to the resource.
*
* @param {import('../types.js').ListRequestOptions} [options]
*/
async list(options = {}) {
const conf = await this._invocationConfig([BlobCapabilities.list.can])
options.connection = this._serviceConf.upload
return Blob.list(conf, options)
}

/**
* Remove a stored CAR file by CAR CID.
*
* @param {import('../types.js').CARLink} link - CID of CAR file to remove.
* @param {import('../types.js').RequestOptions} [options]
*/
async remove(link, options = {}) {
const conf = await this._invocationConfig([BlobCapabilities.remove.can])
options.connection = this._serviceConf.upload
return Blob.remove(conf, link, options)
}
}
1 change: 1 addition & 0 deletions packages/w3up-client/src/capability/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class StoreClient extends Base {
* @param {import('../types.js').ListRequestOptions} [options]
*/
async list(options = {}) {
// FIXME is this capability correct? shouldn't it be a `store/list`?
const conf = await this._invocationConfig([StoreCapabilities.add.can])
options.connection = this._serviceConf.upload
return Store.list(conf, options)
Expand Down
4 changes: 3 additions & 1 deletion packages/w3up-client/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import {
uploadCAR,
} from '@web3-storage/upload-client'
import {
Store as StoreCapabilities,
Blob as BlobCapabilities,
Upload as UploadCapabilities,
} from '@web3-storage/capabilities'
import { CAR } from '@ucanto/transport'
import { Base } from './base.js'
import * as Account from './account.js'
import { Space } from './space.js'
import { Delegation as AgentDelegation } from './delegation.js'
import { BlobClient } from './capability/blob.js'
import { StoreClient } from './capability/store.js'
import { UploadClient } from './capability/upload.js'
import { SpaceClient } from './capability/space.js'
Expand Down Expand Up @@ -46,6 +47,7 @@ export class Client extends Base {
access: new AccessClient(agentData, options),
filecoin: new FilecoinClient(agentData, options),
space: new SpaceClient(agentData, options),
blob: new BlobClient(agentData, options),
store: new StoreClient(agentData, options),
subscription: new SubscriptionClient(agentData, options),
upload: new UploadClient(agentData, options),
Expand Down

0 comments on commit 5196f9c

Please sign in to comment.