Skip to content

Commit d13d15f

Browse files
vmxrvaggachingbrain
authored
feat: upgrade to the new multiformats (ipfs#3556)
- Replaces the old [interface-ipld-format](https://github.com/ipld/interface-ipld-format) stack with the new [multiformats](https://github.com/multiformats/js-multiformats) stack. - The Block API takes/returns `Uint8Array`s instead of [ipld-block](https://github.com/ipld/js-ipld-block) objects BREAKING CHANGE: ipld-formats no longer supported, use multiformat BlockCodecs instead Co-authored-by: Rod Vagg <[email protected]> Co-authored-by: achingbrain <[email protected]>
1 parent dc041aa commit d13d15f

File tree

476 files changed

+6057
-5885
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

476 files changed

+6057
-5885
lines changed

.github/workflows/bundlesize.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest # https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu1804-README.md
1111
strategy:
1212
matrix:
13-
node-version: [14.x]
13+
node-version: [16.x]
1414
project:
1515
- packages/ipfs
1616
- packages/ipfs-core

.github/workflows/typecheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
node-version: [14.x]
12+
node-version: [16.x]
1313
project:
1414
- packages/ipfs
1515
- packages/ipfs-cli

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dist
2121
build
2222
bundle.js
2323
tsconfig-types.aegir.json
24+
tsconfig-check.aegir.json
2425
.tsbuildinfo
2526

2627
# Deployment files

README.md

Lines changed: 19 additions & 12 deletions
Large diffs are not rendered by default.

docs/MIGRATION-TO-ASYNC-AWAIT.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,20 @@ Libp2p `PeerId` instances are no longer returned from the API. If your applicati
9494
Peer ID strings are also CIDs so converting them is simple:
9595

9696
```js
97-
const peerId = PeerId.createFromCID(peerIdStr)
97+
const peerId = PeerId.createFromB58String(peerIdStr)
9898
```
9999

100100
You can get hold of the `PeerId` class using npm or in a script tag:
101101

102102
```js
103103
const PeerId = require('peer-id')
104-
const peerId = PeerId.createFromCID(peerIdStr)
104+
const peerId = PeerId.createFromB58String(peerIdStr)
105105
```
106106

107107
```html
108108
<script src="https://unpkg.com/peer-id/dist/index.min.js"></script>
109109
<script>
110-
const peerId = window.PeerId.createFromCID(peerIdStr)
110+
const peerId = window.PeerId.createFromB58String(peerIdStr)
111111
</script>
112112
```
113113

@@ -120,7 +120,7 @@ Libp2p `PeerInfo` instances are no longer returned from the API. Instead, plain
120120
Instantiate a new `PeerInfo` and add addresses to it:
121121

122122
```js
123-
const peerInfo = new PeerInfo(PeerId.createFromCID(info.id))
123+
const peerInfo = new PeerInfo(PeerId.createFromB58String(info.id))
124124
info.addrs.forEach(addr => peerInfo.multiaddrs.add(addr))
125125
```
126126

@@ -129,15 +129,15 @@ You can get hold of the `PeerInfo` class using npm or in a script tag:
129129
```js
130130
const PeerInfo = require('peer-info')
131131
const PeerId = require('peer-id')
132-
const peerInfo = new PeerInfo(PeerId.createFromCID(info.id))
132+
const peerInfo = new PeerInfo(PeerId.createFromB58String(info.id))
133133
info.addrs.forEach(addr => peerInfo.multiaddrs.add(addr))
134134
```
135135

136136
```html
137137
<script src="https://unpkg.com/peer-info/dist/index.min.js"></script>
138138
<script src="https://unpkg.com/peer-id/dist/index.min.js"></script>
139139
<script>
140-
const peerInfo = new window.PeerInfo(window.PeerId.createFromCID(info.id))
140+
const peerInfo = new window.PeerInfo(window.PeerId.createFromB58String(info.id))
141141
info.addrs.forEach(addr => peerInfo.multiaddrs.add(addr))
142142
</script>
143143
```

docs/core-api/BLOCK.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ console.log(block.cid.toString())
105105
// the CID of the object
106106

107107
// With custom format and hashtype through CID
108-
const CID = require('cids')
108+
const { CID } = require('multiformats/cid')
109+
const dagPb = require('@ipld/dag-pb')
109110
const buf = new TextEncoder().encode('another serialized object')
110-
const cid = new CID(1, 'dag-pb', multihash)
111+
const cid = CID.createV1(dagPb.code, multihash)
111112

112113
const block = await ipfs.block.put(blob, cid)
113114

@@ -211,7 +212,7 @@ the returned object has the following keys:
211212

212213
```JavaScript
213214
const multihashStr = 'QmQULBtTjNcMwMr4VMNknnVv3RpytrLSdgpvMcTnfNhrBJ'
214-
const cid = new CID(multihashStr)
215+
const cid = CID.parse(multihashStr)
215216

216217
const stats = await ipfs.block.stat(cid)
217218
console.log(stats.cid.toString())

docs/core-api/DAG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ An optional object which may have the following keys:
6262

6363
```JavaScript
6464
const obj = { simple: 'object' }
65-
const cid = await ipfs.dag.put(obj, { format: 'dag-cbor', hashAlg: 'sha3-512' })
65+
const cid = await ipfs.dag.put(obj, { format: 'dag-cbor', hashAlg: 'sha2-512' })
6666

6767
console.log(cid.toString())
6868
// zBwWX9ecx5F4X54WAjmFLErnBT6ByfNxStr5ovowTL7AhaUR98RWvXPS1V3HqV1qs3r5Ec5ocv7eCdbqYQREXNUfYNuKG

docs/core-api/OBJECT.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ An optional object which may have the following keys:
343343
const cid = await ipfs.object.patch.addLink(node, {
344344
name: 'some-link',
345345
size: 10,
346-
cid: new CID('QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD')
346+
cid: CID.parse('QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD')
347347
})
348348
```
349349

@@ -357,7 +357,7 @@ The `DAGLink` to be added can also be passed as an object containing: `name`, `c
357357
const link = {
358358
name: 'Qmef7ScwzJUCg1zUSrCmPAz45m8uP5jU7SLgt2EffjBmbL',
359359
size: 37,
360-
cid: new CID('Qmef7ScwzJUCg1zUSrCmPAz45m8uP5jU7SLgt2EffjBmbL')
360+
cid: CID.parse('Qmef7ScwzJUCg1zUSrCmPAz45m8uP5jU7SLgt2EffjBmbL')
361361
};
362362
```
363363

@@ -400,7 +400,7 @@ An optional object which may have the following keys:
400400
const cid = await ipfs.object.patch.rmLink(node, {
401401
name: 'some-link',
402402
size: 10,
403-
cid: new CID('QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD')
403+
cid: CID.parse('QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD')
404404
})
405405
```
406406

docs/core-api/PIN.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ An optional object which may have the following keys:
8686
### Example
8787

8888
```JavaScript
89-
const cid of ipfs.pin.add(new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))
89+
const cid of ipfs.pin.add(CID.parse('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))
9090
console.log(cid)
9191
// Logs:
9292
// CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u')
@@ -130,7 +130,7 @@ Each yielded object has the form:
130130
### Example
131131

132132
```JavaScript
133-
for await (const cid of ipfs.pin.addAll(new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))) {
133+
for await (const cid of ipfs.pin.addAll(CID.parse('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))) {
134134
console.log(cid)
135135
}
136136
// Logs:
@@ -178,7 +178,7 @@ for await (const { cid, type } of ipfs.pin.ls()) {
178178

179179
```JavaScript
180180
for await (const { cid, type } of ipfs.pin.ls({
181-
paths: [ new CID('Qmc5..'), new CID('QmZb..'), new CID('QmSo..') ]
181+
paths: [ CID.parse('Qmc5..'), CID.parse('QmZb..'), CID.parse('QmSo..') ]
182182
})) {
183183
console.log({ cid, type })
184184
}
@@ -218,7 +218,7 @@ An optional object which may have the following keys:
218218
### Example
219219

220220
```JavaScript
221-
const cid of ipfs.pin.rm(new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))
221+
const cid of ipfs.pin.rm(CID.parse('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))
222222
console.log(cid)
223223
// prints the CID that was unpinned
224224
// CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u')
@@ -254,7 +254,7 @@ An optional object which may have the following keys:
254254
### Example
255255

256256
```JavaScript
257-
for await (const cid of ipfs.pin.rmAll(new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))) {
257+
for await (const cid of ipfs.pin.rmAll(CID.parse('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))) {
258258
console.log(cid)
259259
}
260260
// prints the CIDs that were unpinned
@@ -320,7 +320,7 @@ An object may have the following optional fields:
320320

321321
| Name | Type | Default | Description |
322322
| ---- | ---- | ------- | ----------- |
323-
| stat | `boolean` | `false` | If `true` will include service stats. |
323+
| stat | `boolean` | `false` | If `true` will include service stats. |
324324
| timeout | `number` | `undefined` | A timeout in ms |
325325
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |
326326

@@ -486,7 +486,7 @@ Status is one of the following string values:
486486
### Example
487487

488488
```JavaScript
489-
const cid = new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u')
489+
const cid = CID.parse('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u')
490490
const pin = await ipfs.pin.remote.add(cid, {
491491
service: 'pinata',
492492
name: 'block-party'

examples/browser-add-readable-stream/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ const main = async () => {
1414

1515
const directoryHash = await streamFiles(ipfs, directoryName, inputFiles)
1616

17-
const fileList = await ipfs.ls(directoryHash)
18-
1917
log(`\n--\n\nDirectory contents:\n\n${directoryName}/ ${directoryHash}`)
2018

21-
fileList.forEach((file, index) => {
22-
log(` ${index < fileList.length - 1 ? '\u251C' : '\u2514'}\u2500 ${file.name} ${file.path} ${file.hash}`)
23-
})
19+
let index = 0
20+
21+
for await (const file of ipfs.ls(directoryHash)) {
22+
log(` ${index < inputFiles.length - 1 ? '\u251C' : '\u2514'}\u2500 ${file.name} ${file.path} ${file.cid}`)
23+
index++
24+
}
2425
}
2526

2627
const createFiles = (directory) => {
@@ -54,7 +55,7 @@ const streamFiles = async (ipfs, directory, files) => {
5455

5556
const data = await ipfs.add(stream)
5657

57-
log(`Added ${data.path} hash: ${data.hash}`)
58+
log(`Added ${data.path} hash: ${data.cid}`)
5859

5960
// The last data event will contain the directory hash
6061
if (data.path === directory) {

0 commit comments

Comments
 (0)