Skip to content

Commit 42a0544

Browse files
author
Alan Shaw
authored
feat: update docs for client v15 (#93)
v15 reduces the amount of code and additional dependencies required to be installed to make for better DX.
1 parent cf262fb commit 42a0544

File tree

4 files changed

+23
-64
lines changed

4 files changed

+23
-64
lines changed

src/pages/docs/concepts/architecture-options.mdx

+5-16
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ A code example that does this can be found below:
7878
**Backend**
7979

8080
```js
81-
import { CarReader } from '@ipld/car'
82-
import * as DID from '@ipld/dag-ucan/did'
83-
import * as Delegation from '@ucanto/core/delegation'
84-
import * as Signer from '@ucanto/principal/ed25519'
8581
import * as Client from '@web3-storage/w3up-client'
8682
import { StoreMemory } from '@web3-storage/w3up-client/stores/memory'
83+
import * as Proof from '@web3-storage/w3up-client/proof'
84+
import { Signer } from '@web3-storage/w3up-client/principal/ed25519'
85+
import * as DID from '@ipld/dag-ucan/did'
8786

8887
async function backend(did) {
8988
// Load client with specific private key
@@ -92,7 +91,7 @@ async function backend(did) {
9291
const client = await Client.create({ principal, store })
9392

9493
// Add proof that this agent has been delegated capabilities on the space
95-
const proof = await parseProof(process.env.PROOF)
94+
const proof = await Proof.parse(process.env.PROOF)
9695
const space = await client.addSpace(proof)
9796
await client.setCurrentSpace(space.did())
9897

@@ -106,22 +105,12 @@ async function backend(did) {
106105
const archive = await delegation.archive()
107106
return archive.ok
108107
}
109-
110-
/** @param {string} data Base64 encoded CAR file */
111-
async function parseProof(data) {
112-
const blocks = []
113-
const reader = await CarReader.fromBytes(Buffer.from(data, 'base64'))
114-
for await (const block of reader.blocks()) {
115-
blocks.push(block)
116-
}
117-
return Delegation.importDAG(blocks)
118-
}
119108
```
120109

121110
**Frontend**
122111

123112
```js
124-
import * as Delegation from '@ucanto/core/delegation'
113+
import * as Delegation from '@web3-storage/w3up-client/delegation'
125114
import * as Client from '@web3-storage/w3up-client'
126115

127116
async function frontend() {

src/pages/docs/concepts/car.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,13 @@ The [`@ipld/car`](https://github.com/ipld/js-car) package contains the main Java
9898
Here's a simple example of loading a CAR file from a Node.js stream and storing it with web3.storage:
9999

100100
```js
101-
import { createReadStream } from 'fs'
102-
import { CarReader } from '@ipld/car'
101+
import fs from 'node:fs'
102+
import { Readable } from 'node:stream'
103103

104104
async function storeCarFile(filename) {
105-
const inStream = createReadStream(filename)
106-
const car = await CarReader.fromIterable(inStream)
105+
const stream = () => Readable.toWeb(fs.createReadStream(filename))
107106
const client = makeStorageClient()
108-
const cid = await client.uploadCAR(car)
107+
const cid = await client.uploadCAR({ stream })
109108
console.log('Stored CAR file! CID:', cid)
110109
}
111110
```
@@ -114,7 +113,7 @@ CarReader.fromIterable accepts any iterable of Uint8Array data, including Node.j
114113

115114
The CarReader type shown above will read the entire contents of the CAR into memory, which may cause issues with large files. On Node.js, you can use [CarIndexedReader](https://github.com/ipld/js-car#carindexedreader), which reads CAR data from disk directly and uses less memory than CarReader.
116115

117-
## [Advanced IPLD formats](https://web3.storage/docs/how-tos/work-with-car-files/#advanced-ipld-formats)
116+
## Advanced IPLD formats
118117

119118
IPLD can also be used as a general purpose data format like JSON. In fact, you can use JSON directly as IPLD just by using a special convention for linking to other IPLD objects. This convention is defined in the [dag-json](https://ipld.io/docs/codecs/known/dag-json/)["codec"](https://ipld.io/docs/codecs/known/dag-json/).
120119

@@ -124,7 +123,7 @@ Here's an example of a `dag-json` object:
124123
{
125124
"name": "Have you seen this dog?",
126125
"description": "I have now...",
127-
"image":{"/":"bafybeihkqv2ukwgpgzkwsuz7whmvneztvxglkljbs3zosewgku2cfluvba"}
126+
"image": { "/": "bafybeihkqv2ukwgpgzkwsuz7whmvneztvxglkljbs3zosewgku2cfluvba" }
128127
}
129128
```
130129

src/pages/docs/how-to/remove.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ To remove shard CIDs and upload CIDs separately, you'll generally do this by:
5454
- Client: `client.capability.upload.remove(contentCID)`
5555
- CLI: `w3 can upload rm <contentCID>`
5656
1. Remove each of the shards (ensure first that no other content is using that shard!):
57-
- Client: `client.capability.store.remove(shardCID)`
58-
- CLI: `w3 can store rm <shardCID>`
57+
- Client: `client.capability.blob.remove(shardMultihash)`
58+
- CLI: `w3 can blob rm <shardMultihash>`

src/pages/docs/how-to/upload.mdx

+10-39
Original file line numberDiff line numberDiff line change
@@ -131,48 +131,30 @@ w3 key create
131131
# If you want to limit permissions being passed to the Agent, you can specify
132132
# permissions to give, e.g., `--can space/blob/add --can space/index/add --can
133133
# filecoin/offer --can upload/add` limits to just being able to upload.
134-
w3 delegation create <did_from_ucan-key_command_above> | base64
134+
w3 delegation create <did_from_ucan-key_command_above> --base64
135135

136136
# ❗️ Store the output in environment variable PROOF
137137
```
138138

139-
Then, when you initialize and configure the client, you can pass in this Agent and UCAN.
139+
Then, when you initialize and configure the client, you can pass in this private key and UCAN delegation.
140140

141141
```javascript
142142
import * as Client from '@web3-storage/w3up-client'
143143
import { StoreMemory } from '@web3-storage/w3up-client/stores/memory'
144-
import { importDAG } from '@ucanto/core/delegation'
145-
import { CarReader } from '@ipld/car'
146-
import * as Signer from '@ucanto/principal/ed25519'
144+
import * as Proof from '@web3-storage/w3up-client/proof'
145+
import { Signer } from '@web3-storage/w3up-client/principal/ed25519'
147146

148147
async function main () {
149148
// Load client with specific private key
150149
const principal = Signer.parse(process.env.KEY)
151150
const store = new StoreMemory()
152151
const client = await Client.create({ principal, store })
153152
// Add proof that this agent has been delegated capabilities on the space
154-
const proof = await parseProof(process.env.PROOF)
153+
const proof = await Proof.parse(process.env.PROOF)
155154
const space = await client.addSpace(proof)
156155
await client.setCurrentSpace(space.did())
157156
// READY to go!
158157
}
159-
160-
/** @param {string} data Base64 encoded CAR file */
161-
async function parseProof (data) {
162-
const blocks = []
163-
const reader = await CarReader.fromBytes(Buffer.from(data, 'base64'))
164-
for await (const block of reader.blocks()) {
165-
blocks.push(block)
166-
}
167-
return importDAG(blocks)
168-
}
169-
```
170-
171-
If you're doing this in a non-persistent or serverless backend, you might consider using an in-memory [Store](https://github.com/web3-storage/w3up/tree/main/packages/access-client) for your Agent information rather than the default on-disk:
172-
173-
```javascript
174-
import { StoreMemory } from '@web3-storage/access/stores/store-memory'
175-
const client = await Client.create({ principal, store: new StoreMemory() })
176158
```
177159

178160
### Uploading to web3.storage
@@ -226,12 +208,11 @@ Your backend instance can also be used to delegate upload permissions directly t
226208
**Backend**
227209

228210
```js
229-
import { CarReader } from '@ipld/car'
230-
import * as DID from '@ipld/dag-ucan/did'
231-
import * as Delegation from '@ucanto/core/delegation'
232-
import * as Signer from '@ucanto/principal/ed25519'
233211
import * as Client from '@web3-storage/w3up-client'
234212
import { StoreMemory } from '@web3-storage/w3up-client/stores/memory'
213+
import * as Proof from '@web3-storage/w3up-client/proof'
214+
import { Signer } from '@web3-storage/w3up-client/principal/ed25519'
215+
import * as DID from '@ipld/dag-ucan/did'
235216

236217
async function backend(did) {
237218
// Load client with specific private key
@@ -240,7 +221,7 @@ async function backend(did) {
240221
const client = await Client.create({ principal, store })
241222

242223
// Add proof that this agent has been delegated capabilities on the space
243-
const proof = await parseProof(process.env.PROOF)
224+
const proof = await Proof.parse(process.env.PROOF)
244225
const space = await client.addSpace(proof)
245226
await client.setCurrentSpace(space.did())
246227

@@ -254,22 +235,12 @@ async function backend(did) {
254235
const archive = await delegation.archive()
255236
return archive.ok
256237
}
257-
258-
/** @param {string} data Base64 encoded CAR file */
259-
async function parseProof(data) {
260-
const blocks = []
261-
const reader = await CarReader.fromBytes(Buffer.from(data, 'base64'))
262-
for await (const block of reader.blocks()) {
263-
blocks.push(block)
264-
}
265-
return Delegation.importDAG(blocks)
266-
}
267238
```
268239

269240
**Frontend**
270241

271242
```js
272-
import * as Delegation from '@ucanto/core/delegation'
243+
import * as Delegation from '@web3-storage/w3up-client/delegation'
273244
import * as Client from '@web3-storage/w3up-client'
274245

275246
async function frontend() {

0 commit comments

Comments
 (0)