You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import*asClientfrom'@web3-storage/w3up-client'import{StoreMemory}from'@web3-storage/w3up-client/stores/memory'import{importDAG}from'@ucanto/core/delegation'import{CarReader}from'@ipld/car'import*asSignerfrom'@ucanto/principal/ed25519'asyncfunctionmain(){// Load client with specific private keyconstprincipal=Signer.parse(process.env.KEY)conststore=newStoreMemory()constclient=awaitClient.create({ principal, store })// Add proof that this agent has been delegated capabilities on the spaceconstproof=awaitparseProof(process.env.PROOF)constspace=awaitclient.addSpace(proof)awaitclient.setCurrentSpace(space.did())// READY to go!}/** @param {string} data Base64 encoded CAR file */asyncfunctionparseProof(data){constblocks=[]constreader=awaitCarReader.fromBytes(Buffer.from(data,'base64'))forawait(constblockofreader.blocks()){blocks.push(block)}// 👇 type error for this callreturnimportDAG(blocks)}
When trying this, I get the following type error
Argument of type 'Block[]' is not assignable to parameter of type 'Iterable<Block<unknown, number, number, 1>>'.
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
Type 'IteratorResult<Block, any>' is not assignable to type 'IteratorResult<Block<unknown, number, number, 1>, any>'.
Type 'IteratorYieldResult<Block>' is not assignable to type 'IteratorResult<Block<unknown, number, number, 1>, any>'.
Type 'IteratorYieldResult<Block>' is not assignable to type 'IteratorYieldResult<Block<unknown, number, number, 1>>'.
Type 'Block' is not assignable to type 'Block<unknown, number, number, 1>'.
The types of 'cid.version' are incompatible between these types.
Type 'Version' is not assignable to type '1'.
Type '0' is not assignable to type '1'.ts(2345)
Another thing is that the example is for Node.js and doesn't work out of the box in modern runtimes like cloudflare workers. It's probably worth mentioning or even providing an alternate example.
Errors/warnings in Cloudflare workers:
▲ [WARNING] Import "Readable" will always be undefined because the file "(disabled):stream" has no exports [import-is-undefined]
Buffers don't exist, so the base64 encoded proof has to be converted into a Uint8Array which is rather cumbersome.
The text was updated successfully, but these errors were encountered:
The docs give the following code for uploading:
When trying this, I get the following type error
Another thing is that the example is for Node.js and doesn't work out of the box in modern runtimes like cloudflare workers. It's probably worth mentioning or even providing an alternate example.
Errors/warnings in Cloudflare workers:
▲ [WARNING] Import "Readable" will always be undefined because the file "(disabled):stream" has no exports [import-is-undefined]
The text was updated successfully, but these errors were encountered: