Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

feat!: consume upload and access client #58

Merged
merged 37 commits into from Dec 14, 2022

Conversation

alanshaw
Copy link
Member

@alanshaw alanshaw commented Dec 7, 2022

This PR updates w3up-client to consume the access-client and upload-client modules. It brings:

  • Convenience methods for storing files/directories and registering uploads
  • Automatic CAR sharding
  • Support for store/upload list pagination
  • Automatic data store selection (IndexedDB in browser, Conf in Node.js)
  • Automatic key selection (RSA in browser, Ed25519 in Node.js)
  • 100% test coverage

It exports the following API:

export class Client {
  /* passthroughs to `upload-client` */
  uploadFile(file: Blob, options: UploadOptions): Promise<CID>
  uploadDirectory(dir: File[], options: UploadOptions): Promise<CID>

  /* passthroughs to `access-client` */
  agent(): Signer
  // space management
  currentSpace(): Space|undefined
  setCurrentSpace(did: DID): Promise<void>
  spaces(): Space[]
  createSpace(name?: string): Promise<DID>
  registerSpace(email: string): Promise<void>
  addSpace(proof: Delegation): Promise<void>
  // capability management
  proofs(): Delegation[]
  addProof(proof: Delegation): Promise<void>
  delegations(): Delegation[]
  createDelegation(audience: Principal, abilities: Abilities[], options: DelegationOptions): Delegation

  /* Advanced API - grouped by capability namespace: *************************/

  capability: {
    /* passthroughs to `upload-client` */
    store: {
      add(carBytes: Blob, options: RequestOptions): Promise<CID>
      remove(carCID: CID, options: RequestOptions): Promise<void>
      list(options: ListRequestOptions): Promise<ListResponse<StoreListResult>>
    }
  
    /* passthroughs to `upload-client` */
    upload: {
      add(root: CID, shards: CID[], options: RequestOptions): Promise<void>
      remove(root: CID, options: RequestOptions): Promise<void>
      list(options: ListRequestOptions): Promise<ListResponse<UploadListResult>>
    }
  
    /* passthroughs to `access-client` */
    space {
      info(space: DID): Promise<SpaceInfo>
      recover(space: DID, email: string): Promise<void>
    }
  }
}

export function create(options?: ClientFactoryOptions): Promise<Client>

resolves #56

BREAKING CHANGE: The client has been re-written as a wrapper around access-client and upload-client and the API has changed. Migration notes:

  • client.account() has been removed, use client.currentSpace()
  • client.exportDelegation() has been removed, use client.createDelegation() and then call export() on the returned value and encode the returned blocks as a CAR file using the @ipld/car library.
  • client.identity() has been removed, use client.agent() + client.currentSpace() + client.delegations()
  • client.importDelegation() has been removed, use client.addProof() (for general delegations to your agent) or client.addSpace() (to add a proof and also add the space to your list of spaces).
  • client.insights() has been removed - this was never working
  • client.invoke() has been removed
  • client.list() has been removed, use client.capability.upload.list()
  • client.makeDelegation() has been renamed and signature has changed, use client.createDelegation()
  • client.register() has been removed, use client.registerSpace()
  • client.remove() has been removed, use client.capability.store.remove()
  • client.removeUpload() has been removed, use client.capability.upload.remove()
  • client.stat() has been removed, use client.capability.store.list()
  • client.upload() has been removed, use client.capability.store.add()
  • client.uploadAdd() has been removed, use client.capability.upload.add()
  • client.whoami() has been removed, use client.capability.space.info()

@alanshaw alanshaw marked this pull request as ready for review December 8, 2022 13:14
@alanshaw alanshaw changed the title feat: consume upload and access client feat!: consume upload and access client Dec 8, 2022
@alanshaw alanshaw merged commit 7bd91d5 into main Dec 14, 2022
@alanshaw alanshaw deleted the feat/consume-upload-and-access-client branch December 14, 2022 11:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consume upload-client and access-client
2 participants